Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL int definition explanation

For years I have been under the assumption when I create a new column of type bigint(12) for a MySQL table that the field is limited to integers with up to 12 digits. However, I recently noticed that values up to 16 digits are able to be written into and selected out of a bigint(12) defined column without any warnings or issues.

Can someone please help me understand why this is the case and what that column definition actually means? Thanks in advance!

like image 665
Russell C. Avatar asked Dec 14 '25 22:12

Russell C.


1 Answers

bigint(12) is not truncated at all. The 12 is used for display purposes.

Have a look at Numeric Types

Numeric Type Attributes

MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly.

like image 86
Adriaan Stander Avatar answered Dec 16 '25 13:12

Adriaan Stander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!