Skip to content

Commit 45fa491

Browse files
committed
Add extra_float_digits connection option defaulted to 3
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.
1 parent b92ddbc commit 45fa491

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/client.js

+5
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ Client.prototype.getStartupConf = function() {
208208
data.application_name = appName;
209209
}
210210

211+
var extraFloatDigits = params.extra_float_digits;
212+
if( extraFloatDigits ) {
213+
data.extra_float_digits = String(extraFloatDigits);
214+
}
215+
211216
return data;
212217
};
213218

lib/connection-parameters.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var ConnectionParameters = function(config) {
4848

4949
this.application_name = val('application_name', config, 'PGAPPNAME');
5050
this.fallback_application_name = val('fallback_application_name', config, false);
51+
this.extra_float_digits = val('extra_float_digits', config, false);
5152
};
5253

5354
var add = function(params, config, paramName) {

lib/defaults.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ var defaults = module.exports = {
4141
ssl: false,
4242

4343
application_name : undefined,
44-
fallback_application_name: undefined
44+
fallback_application_name: undefined,
45+
46+
//number of digits displayed for floating-point values
47+
//set to 0 to suppress sending it as part of the startup packet
48+
//must be explicitly set to 0 to for driver to work with PG <= 8.4
49+
extra_float_digits: 3
4550
};
4651

4752
//parse int8 so you can get your count values as actual numbers

0 commit comments

Comments
 (0)