'Aurora mysql serverless 5.6 BIGINT unsigned column rounding after 16 digits
For some reason when I insert a value to my Aurora serverless db cluster mysql 5.6, big int column it gets rounded after 16 digits.
Example:
- 734783792502575105 saves as 734783792502575100
- 9223372036854775807 saves as 9223372036854776000
My column is defined as -> bigint(20) unsigned NOT NULL.
Isn't unsigned BIGINT supposed to be able to have a max value 18446744073709551615?
EDIT:
Even stranger is that I am able to insert 18446744073709551615 into the column but when I try to run a regular select on the table after the insert I start getting the following error: "Value '18,446,744,073,709,551,615' is outside of valid range for type java.lang.Long"
I tested the queries in the Query Editor in the AWS dashboard and also through aws RDSDataService lib for nodejs.
Thx
Solution 1:[1]
After running into this weird problem myself I found out that there is a setting in serverless-mysql to force bigInt into strings so the rounding error won't occur. It's on this page mysql options.
Here a snippet for setting the mysql config in nodeJS:
import mysql from 'serverless-mysql';
export const db = mysql({
config: {
// left out the normal stuff,
supportBigNumbers: true,
bigNumberStrings: true,
},
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | generalcss |
