-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres BigInt Returned As String #4064
Comments
Hi @careygister! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:
As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks! *If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected] |
Ok, fixed! |
@careygister Thanks for posting, we'll take a look as soon as possible. For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here. |
I had a play with this a while back and as annoying as this is, after deeper research I do believe this is the correct behavior. JavaScript's Number.MAX_SAFE_INTEGER is 9007199254740991 = 2^53-1. There's a very real possibility for Postgres' BigInt to overflow JavaScript. When using numbers > MAX_SAFE_INTEGER, no errors or warnings are thrown (AFAIK) but the value is no longer true. Try it yourself by pasting Postgres' BigInt max into the console. With that in mind, I guess I can't help but feel that I'd rather my ORM return an accurate string representation and leave it to me to typecast or manipulate using a library such as big-integer or bignum. BigInts as strings is pretty common in JS land, for example (twitter's JSON API returns the 64-bit int ID both as number and as string)[https://dev.twitter.com/overview/api/tweets] so you still have access to the correct ID. |
Yup that's correct. It's actually happening at the node-pg level. I think they expose their parsers if you really wanted to override it though. |
Sails version: 0.12.13
Node version: v6.9.4
NPM version: 3.10.10
Operating system: 4.9.13-moby Linux x86_64
I am using an existing set of Postgres tables in my Sails models. The tables have BigInt datatypes. I specified 'integer' as the type, assuming that Javascript native integers or numbers were used. I found that the returned datatype from a 'find' was a string. How can I model a Bigint?
Note: the native precision of Javascript numbers permits the representation of a Postgres Bigint.
Thank you.
The text was updated successfully, but these errors were encountered: