I am running the query 'select count(*) from foo' and it return the count as a string type. Is there a way that I can make the count as a number without explicitly casting it using Number().
Is there a way that I can make the count as a number without explicitly casting it using Number().
No.
See also in the demo: https://github.com/vitaly-t/pg-promise-demo/blob/master/JavaScript/db/repos/products.js
total: () => rep.one("SELECT count(*) FROM Products")
.then(data => parseInt(data.count))
that's the way to do it.
I see pg-promise uses node-postgres, is it the implementation of node-postgres or it is just the natural behavior of postgres itself?
I honestly don't know. You can check that yourself. All type conversions are done by pg-types.
Thanks, I will check it out there. :smiley:
@OnionCoder did you get to the bottom of it?
When I call count(*) in postgres it returns a 64-bit bigint type number. But Javascirpt does not support 64-bit integers (which is also mentioned in pg-types). So it will be converted to string.
Proper explanation: pg-promise returns integers as strings.
Further development on the subject - BigInt Support.
Most helpful comment
When I call count(*) in postgres it returns a 64-bit bigint type number. But Javascirpt does not support 64-bit integers (which is also mentioned in pg-types). So it will be converted to string.