I need to store twitter tweet ID numbers, and these numbers are big, like 16 digits big. I was wondering wheter to use bigint in mysql to store them? or is there another alternative. How many digits can bigint handle? I tried looking at the specs but it was not clear. What are the limitations of storing such big numbers in mysql table? thanks!
BIGINT takes 8 bytes i.e. 64 bits. The signed range is -9223372036854775808 to 9223372036854775807 and unsigned range takes positive value. The range of unsigned is 0 to 18446744073709551615.
The bigint data type is intended for use when integer values might exceed the range that is supported by the int data type. bigint fits between smallmoney and int in the data type precedence chart. Functions return bigint only if the parameter expression is a bigint data type.
If you have BIGINT(20) for system this means allocate in memory minimum 20 bits. But if you'll insert value that bigger than 2^20 , it will be stored successfully, if it's less then BIGINT(64) -> 9223372036854775807 (or 2 * BIGINT(64) -> 18446744073709551615 for UNSIGNED )
A big integer is a binary integer with a precision of 63 bits. The range of big integers is -9223372036854775808 to +9223372036854775807.
A bigint is 64bit, which goes -9223372036854775808 to 9223372036854775807 signed, and 0 to 18446744073709551615 unsigned, as per the mysql docs.
Even if currently the IDs fit on a BIGINT (64bit signed), when the ID generation is outside your control, it's safer to store as a text string.
Not only it could grow even bigger (well, it's unlikely to ever overflow a BIGINT); but also you could later on add a prefix and store IDs from other systems in the same table. Or maybe some future API could use non-numerical IDs
From the MySQL manual
BIGINT[(M)] [UNSIGNED] [ZEROFILL]
A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With