-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
lose precision when querying large double precision values #730
Comments
Add a failing test for roundtripping large double precision values. This test will fail with the default extra_float_digits. Reproduces brianc#730
Add a connection option for setting extra_float_digits and set its default value to 3. This allows for more accurate representation of large floating point values. The option is sent in the connection startup packet so as not to incur an extra round trip. This will not work with older database that do not support setting the extra_float_digits connection parameter in the startup packet (PostgreSQL versions <=8.4). Closes brianc#730 WARNING: This is a breaking change and will prevent connecting to older (<=8.4) databases unless extra_float_digits is set to 0.
I've put together a WIP patch that corrects this behavior. It adds an Couple of points/issues as it's definitely not ready to be merged in:
Real question is: Normally, I'd side with doing our best to maintain backwards compatibility. The annoying part with that is it means everybody would need to add an Either way, I'd like however it's implemented to have the value sent in the startup packet vs being sent afterwards in a separate "SET extra_float_digits = ..." query. The JDBC driver does that for fallback handling and it's both slower (extra roundtrip for connection setup) and annoying (cruft in pg_stat_activity). |
@brianc any thoughts on this? |
@brianc any comment at all? |
I think this one deserves some attention, maybe @brianc would like to chime in? |
node-postgres shouldn't be parsing numbers longer than JavaScript can handle into number objects by default. They should return as strings unless that behavior is manually over-ridden in your app. If this is still an issue please open an issue at http://github.com/brianc/node-pg-types |
FYI: I think this has been fixed. |
Can I change extra_float_digits to 6, if available? @brianc you said this has been fixed? |
@Fangmingdu It hasn’t been fixed, but you can set
Yes, I think it should be a default. |
When querying large double precision values they appear to be rounded.
e.g. the following values are all returned as '2.09999999769e+15'
2099999997689999
2099999997690000
2099999997690001
I believe that is because extra_float_digits should be set to 3 (ideally at protocol level when a connection to the DB is opened):
http://www.postgresql.org/docs/9.3/static/runtime-config-client.html
This appears to be how the PostgreSQL JDBC driver works:
https://github.com/pgjdbc/pgjdbc/search?utf8=%E2%9C%93&q=extra_float_digits
PostgreSQL JDBC used to do it at SQL level. This isn't ideal, but I think preferable to getting incorrect values.
pgjdbc/pgjdbc#168
http://stackoverflow.com/questions/24680696/set-extra-float-digits-3-in-postgresql
The text was updated successfully, but these errors were encountered: