我正在使用一个列来存储 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.
关于当数据类型为 bigint(8) 但作为 bigint(20) 失败时,mysql 排序功能正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34488620/