Reputation:
declare x bigint; set x = 180181182149150151152;
Error: Out of range Value for column 'x' at row 1.
So my question is , can i store a big number like the one above inside bigint?
Upvotes: 2
Views: 368
Reputation: 562330
Here's the largest value supported by BIGINT UNSIGNED
, compared to the number you are using:
180181182149150151152 = your number
18446744073709551615 = 2^64-1, largest value for BIGINT UNSIGNED
You can see that your number is on the order of 10x larger than the largest integer value supported by MySQL. Your number would require 68 bits to store, but MySQL only supports integer data types up to 64-bit.
You can store values with larger magnitude in a FLOAT
or DOUBLE
, but you'll lose precision. In other words, the You simply can't stuff 68 bits of information into 64 bits of encoding.
mysql> create procedure p() begin declare x double; set x = 180181182149150151152; select x; end;;
mysql> call p;;
+-----------------------+
| x |
+-----------------------+
| 1.8018118214915015e20 |
+-----------------------+
You can use DECIMAL()
if you give it enough precision:
mysql> create procedure p() begin declare x decimal(64,0); set x = 180181182149150151152; select x; end;;
mysql> call p;;
+-----------------------+
| x |
+-----------------------+
| 180181182149150151152 |
+-----------------------+
Read more: https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html
Upvotes: 1