Skip to content
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

fix: Precision loss on extremely large floating-point numbers #3093

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/pg-protocol/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const startup = (opts: Record<string, string>): Buffer => {
}

writer.addCString('client_encoding').addCString('UTF8')
writer.addCString('extra_float_digits').addCString('1')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this belongs in pg’s use of startup instead of in pg-protocol. (Side benefit: fewer/no other tests to update, since that’s at least part of why CI is failing right now.)

It also needs to be higher than 1 (take 0.42467013940651843 as a random example), with an accordingly stricter test case. I don’t have time right now to figure out exactly how much precision is enough, but setting it to 3 (https://www.postgresql.org/docs/11/runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS) is probably fine.


var bodyBuffer = writer.addCString('').flush()
// this message is sent without a code
Expand Down
2 changes: 1 addition & 1 deletion packages/pg/test/integration/client/type-coercion-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var types = [
},
{
name: 'double precision',
values: [-101.3, -1.2, 0, 1.2, 101.1, null],
values: [-101.3, -1.2, 0, 1.2, 101.1, Number.MAX_SAFE_INTEGER, null],
},
{
name: 'timestamptz',
Expand Down
Loading