Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best datatype to store 18 digit numeric value in MySQL

Tags:

mysql

rdbms

What is the best data type to store 18 digit numeric value in MySQL

  • The number is always positive
  • This column will be a primary key and partition column
  • The number of precision is always 18
  • The number of decimals is always 0

There are multiple datatypes

BIGINT
FLOAT(18,0)
DECIMAL(18,0)
DOUBLE(18,0)

What is the industry standard and most efficient datatype in MySQL for storage and retrival of such values.

like image 940
Rahul Avatar asked Oct 17 '25 21:10

Rahul


1 Answers

Use BIGINT UNSIGNED. It can support at least 19 digits of precision. The maximum value is 18446744073709551615.

There's no advantage to using DECIMAL, FLOAT, or DOUBLE in this case, because you say the values have no scale.

But you do need 18 digits of precision, so the rounding behavior of FLOAT/DOUBLE may not do what you need.

like image 190
Bill Karwin Avatar answered Oct 19 '25 12:10

Bill Karwin