Skip to content

Commit a438e61

Browse files
author
Sergey Tatarintsev
committed
fix: Precision loss on extremely large floating-point numbers
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
1 parent e8259e0 commit a438e61

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

packages/pg-protocol/src/serializer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const startup = (opts: Record<string, string>): Buffer => {
2626
}
2727

2828
writer.addCString('client_encoding').addCString('UTF8')
29+
writer.addCString('extra_float_digits').addCString('1')
2930

3031
var bodyBuffer = writer.addCString('').flush()
3132
// this message is sent without a code

packages/pg/test/integration/client/type-coercion-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ var types = [
108108
},
109109
{
110110
name: 'double precision',
111-
values: [-101.3, -1.2, 0, 1.2, 101.1, null],
111+
values: [-101.3, -1.2, 0, 1.2, 101.1, Number.MAX_SAFE_INTEGER, null],
112112
},
113113
{
114114
name: 'timestamptz',

0 commit comments

Comments
 (0)