node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

pg numeric return formatting

Open MarkAurit opened this issue 11 years ago • 2 comments

Per the attached, pg returns numerics with quotes and integers without node_numeric

MarkAurit avatar Oct 31 '15 17:10 MarkAurit

You have to specify the type like this:

pg.types.setTypeParser(1700, function(val) { // NUMERIC return val === null ? null : parseFloat(val) }); pg.types.setTypeParser(20, function(val) { // INT8 if(val !== null && val.length >= 16 && val[0] == '9') logger.error('WARNING!!! PG type 20 (int8) value is very likely to be invalid in javascript:',val,'Number.MAX_SAFE_INTEGER',Number.MAX_SAFE_INTEGER); return val === null ? null : parseInt(val) });

ngervasi avatar Oct 31 '15 19:10 ngervasi

@MarkAurit because JavaScript does not support 64 bit numbers we have to return numeric types as strings in case they are larger than 32 bits. There is more information here:

https://github.com/brianc/node-pg-types

brianc avatar Nov 02 '15 16:11 brianc