Skip to content

Commit

Permalink
fix: Precision loss on extremely large floating-point numbers
Browse files Browse the repository at this point in the history
Sets `extra_float_digits` setting to 1 when connecting to DB. For older
(<12) Postgres, this should be enough to cover all values JS can store
preciesely. For 12+ postgres this setting should have no effect.

Fix brianc#3092
  • Loading branch information
SevInf committed Nov 6, 2023
1 parent e8259e0 commit a438e61
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/pg-protocol/src/serializer.ts
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')

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
Expand Up @@ -108,7 +108,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

0 comments on commit a438e61

Please sign in to comment.