Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bigint in mysql

Tags:

php

mysql

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!

like image 861
Chris Hansen Avatar asked Jul 27 '11 22:07

Chris Hansen


People also ask

What is range of BIGINT in MySQL?

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.

What is a BIGINT datatype?

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.

What is BIGINT 20 MySQL?

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 )

What is BIGINT value?

A big integer is a binary integer with a precision of 63 bits. The range of big integers is -9223372036854775808 to +9223372036854775807.


3 Answers

A bigint is 64bit, which goes -9223372036854775808 to 9223372036854775807 signed, and 0 to 18446744073709551615 unsigned, as per the mysql docs.

like image 109
Marc B Avatar answered Oct 22 '22 15:10

Marc B


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

like image 37
Javier Avatar answered Oct 22 '22 14:10

Javier


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

like image 2
Adam Hopkinson Avatar answered Oct 22 '22 14:10

Adam Hopkinson