brianc/node-pg-types

numeric[] should be parsed via parseStringArray(...) not parseFloatArray(...)

Closed this issue · 4 comments

Arrays of numeric type are registered to be parsed as an arrays of floats whereas the non-array numeric is returned as a string to ensure to no loss of precision:

register(1231, parseFloatArray); // _numeric

It should instead return back an array of the string values so the user gets the full value.

This would be a breaking change to anyone previously expecting an array of Numbers.

Good point, would appreciate a PR for this

Yes this shouldn't be much as it's mainly removing special handling so the default string array handling kicks in.

I took a peek at the binary handlers and looks like there's another inconsistency in that case a non-array numeric is returned as a Number:

var parseNumeric = function(value) {
var sign = parseBits(value, 16, 32);
if (sign == 0xc000) {
return NaN;
}
var weight = Math.pow(10000, parseBits(value, 16, 16));
var result = 0;
var digits = [];
var ndigits = parseBits(value, 16);
for (var i = 0; i < ndigits; i++) {
result += parseBits(value, 16, 64 + (16 * i)) * weight;
weight /= 10000;
}
var scale = Math.pow(10, parseBits(value, 16, 48));
return ((sign === 0) ? 1 : -1) * Math.round(result * scale) / scale;
};

Should be a string to match the text format right?

Yes that sounds right. @charmander would you be able to take a look and confirm? Noticed you've worked on this and related packages somewhat recently.

Closed via #88