-
Notifications
You must be signed in to change notification settings - Fork 78
Closed
Labels
Description
Some of our columns are bigints and we're currently using BigNumber.js to work with those values.
My first attempt:
const n = new BigNumber('26000000000000000')
connection.query(`SELECT ?;`, [n], ...)
// SELECT `s` = 1, `e` = 16, `c` = 260, `_isBigNumber` = true
DoingBigNumber.toString()
fixes that:
connection.query(`SELECT ?;`, [n.toString()], ...)
// SELECT '26000000000000000'
But the problem is that quoting numbers causes MySQL to treat the value differently, and lose precision when doing arithmetic (bug):
SELECT 26000000000012345; // 26000000000012345
SELECT '26000000000012345'; // 26000000000012345
SELECT 12345 + 26000000000000000; // 26000000000012345
SELECT 12345 + '26000000000000000'; // 2.6000000000012344e16
Is there a way to use a "?" placeholder to produce an unquoted bigint value?