mysql 数据类型为 bigint(8) 时排序功能正常,但数据类型为 bigint(20) 时排序失败

mysql sort functions properly when datatype is bigint(8) but fails as bigint(20)

我正在使用一个列来存储 UNIX 时间戳(除以 1000)。我发现 bigint 数据类型足以存储它。我使用

创建了它
 ...
 createTimeStamp bigint,
 ...

然而,当我 运行

show create table tablename

它已将其创建为 bigint(20)。直到我的排序开始 运行 出现问题时我才注意到它。然后我修改了架构,使其成为 bigint(8) 明确如:

alter table tablename modify createTimeStamp bigint(8)

而且排序功能很好。

研究了一下发现bigint(20)与存储无关,只是用来填充空格显示的。如果是这样,为什么在使用 bigint(20) 时排序不起作用?

Mysql 暗示使用超过 64 位的数字时会出错。

http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

BIGINT[(M)] [UNSIGNED] [ZEROFILL]

A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615. ... ...

Some things you should be aware of with respect to BIGINT columns:

All arithmetic is done using signed BIGINT or DOUBLE values, so you should not use unsigned big integers larger than 9223372036854775807 (63 bits) except with bit functions! If you do that, some of the last digits in the result may be wrong because of rounding errors when converting a BIGINT value to a DOUBLE.