-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
parseFloat unsuitable for NUMERIC type #107
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
Comments
For anyone else is in this situation here is some nice unstable duct tape:
|
This seems like a reasonable solution, you could always take the string and use some sort of bigint lib outside of |
yeah I think this is a good idea. Question: are numerics used as the sort of 'default' for number columns? I generally stick to int. I could see this breaking backward compatibility of sorts if many people already depend on numerics coming out as javascript numbers. What if the converting function for numerics returned a string only if it was too large for the javascript number type? That's kinda annoying maybe? Also, some pull request I didn't do enough research into has removed the ability for users of node-postgres to easily register their own type converters. Having to do the monkey patch you did above is nasty. I'll re-introduce an easier way to override the built-in converters. |
Agree with the backward compat issue. Having a documented API to register converters would be ideal. |
I think just leaving the existing behavior of parseFloat() might be ok in the interest of backward-compatibility, with the added ability to override the converters. Maybe in the next major release change it to return a string by default? |
I agree with both of you. I'll punch a hole back where there should be one to override and provide custom converters, and put a warning in whenever a numeric type comes back containing a size greater than Number.MAX_VALUE or less than Number.MIN_VALUE saying it will be deprecated in a future release, and you better check yourself before your wreck yourself so they say. :) |
Okay - I added back the ability to override type converters. You can see an example override here: I've also included a warning to stderr if the numeric value retrieved from the database would be truncated if it were passed through parseFloat. This should allow for deprecation & eventually replacing the built-in numeric converter with one having more "smarts." In the meantime, it's totally possible to provide your own numeric type conversion. Thanks for the help & discussion. |
The setTypeParser function is exported, so you should be able to access it https://github.com/brianc/node-postgres/blob/master/lib/types.js#L43 On Tue, Jul 24, 2012 at 7:19 PM, Lalit Kapoor <
|
Indeed you are correct, I realized that shortly after my comment and then promptly deleted my comment :) Thanks for the feedback though! Cheers, On Tuesday, July 24, 2012 at 10:37 PM, Brian Carlson wrote:
|
ah I was wondering why I couldn't see your comment. Was confused so I just responded via email. |
I think columns of type
NUMERIC
should be returned as Strings rather than native javascript numbers.The
NUMERIC
type is for arbitrary precision numbers. Numbers which will fall way outside of what the native max size from V8 will be. Currently if I have huge integers in my database, then fetch them out with node-postgres, it gets run throughparseFloat
, truncated and I'm left with a different number:I think including some kind of BigInt implementation within node-postrges would just cause more problems, so I think it would be best if it just always returned strings for
numeric
columns.The text was updated successfully, but these errors were encountered: