is there a way columns with type bigint can come back to client as integer, not string?
They shouldn't be used as an integer, because bigint is 64-bit, which has no native support in JavaScript.
You can override it within pg-types:
// numeric
pgp.pg.types.setTypeParser(1700, function (value) {
return parseFloat(value);
});
// bigint
pgp.pg.types.setTypeParser(20, function (value) {
return parseInt(value);
});
But that means you will be breaking numbers pass 53 bit.
For further information search issues within the pg library, and pg-types used by node-postgres for all the server-to-client data conversion.
Here's a related discussion: https://github.com/brianc/node-pg-types/issues/39
Best explanation: pg-promise returns integers as strings.
This answer isn't quite right. It will actually be fine until 2โตยณ - 1 because JavaScript number become doubles once they exceed the 32-bit range, giving them 53 bits.
@ForbesLindesay the link that was provided gives all the proper explanation.
Best explanation: pg-promise returns integers as strings.
Update on this topic - BigInt Support.
Most helpful comment
Best explanation: pg-promise returns integers as strings.