Pg-promise: bigint comes back as string instead of integer

Created on 1 May 2016  ยท  5Comments  ยท  Source: vitaly-t/pg-promise

is there a way columns with type bigint can come back to client as integer, not string?

question

Most helpful comment

All 5 comments

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msjoshi picture msjoshi  ยท  4Comments

normanfeltz picture normanfeltz  ยท  4Comments

illarionvk picture illarionvk  ยท  3Comments

calibermind picture calibermind  ยท  3Comments

alpertuna picture alpertuna  ยท  4Comments