0

mysql jdbc: what is column size for BIGINT?

jdbc:

id BIGINT(20)

ResultSet columns = databaseMetaData.getColumns("foo", "bar", "table", "id");
columns.next();
int columnSize = columns.getInt(7);

the columnSize is 19. Is it 19 bytes?

eastwater
  • 4,624
  • 9
  • 49
  • 118

1 Answers1

1

Q: What is column size for BIGINT?

The MySQL BIGINT datatype is a 64-byte signed integer. From a JDBC resultset, that can be handled in Java as a long.

With the unsigned variant, the MySQL BIGINT UNSIGNED dataype, that could be handled as java.math.BigInteger. (The maximum value of MySQL BIGINT UNSIGNED exceeds the maximum value of Java long.)

Q: Is it 19 bytes?

The longest string value that MySQL will return for a BIGINT would be 20 characters. The lowest possible value for a MySQL BIGINT, represented as a character string is '-9223372036854775808'. (That's 19 digits, but an extra character is required for the minus sign.)

The largest value of BIGINT would have a string representation of 19 characters.

For the unsigned variant BIGINT UNSIGNED the largest value would be represented as 20 decimal digits, thus 20 characters.

In terms of storage in the MySQL database, the BIGINT datatype requires eight bytes.

spencer7593
  • 106,611
  • 15
  • 112
  • 140