Skip to content

Commit 472b1fe

Browse files
committed
parse numeric types as string
1 parent d046ffc commit 472b1fe

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ The two share the same interface so __no other code changes should be required__
8181
* async notifications with `LISTEN/NOTIFY`
8282
* bulk import & export with `COPY TO/COPY FROM`
8383
* extensible js<->postgresql data-type coercion
84+
85+
### numeric datatype
86+
Since the `numeric` datatype may have an arbitrary precision,
87+
values of this datatype will be returned as a string from a query. If you need
88+
to do any computations on the value, you should be aware of this, as you may
89+
need to use a JavaScript library for handling the value of arbitrary precision.
90+
91+
Simply taking the value and doing any computation such as addition or subtraction
92+
may lead to unexpected/wrong results since JavaScript will handle the value as
93+
a floating-point number.
8494

8595
## Documentation
8696

lib/textParsers.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ var parseByteA = function(val) {
156156
}
157157
};
158158

159-
var maxLen = Number.MAX_VALUE.toString().length;
160-
161159
var parseInteger = function(val) {
162160
return parseInt(val, 10);
163161
};
@@ -167,14 +165,6 @@ var init = function(register) {
167165
register(21, parseInteger);
168166
register(23, parseInteger);
169167
register(26, parseInteger);
170-
register(1700, function(val){
171-
if(val.length > maxLen) {
172-
console.warn(
173-
'WARNING: value %s is longer than max supported numeric value in ' +
174-
'javascript. Possible data loss', val);
175-
}
176-
return parseFloat(val);
177-
});
178168
register(700, parseFloat);
179169
register(701, parseFloat);
180170
register(16, parseBool);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var types = [{
5858
},{
5959
//TODO get some actual huge numbers here
6060
name: 'numeric',
61-
values: [-12.34, 0, 12.34, null]
61+
values: ['-12.34', '0', '12.34', null]
6262
},{
6363
name: 'real',
6464
values: [101.1, 0, -101.3, null]

test/unit/client/typed-query-results-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test('typed results', function() {
4343
format: 'text',
4444
dataTypeID: 1700,
4545
actual: '12.34',
46-
expected: 12.34
46+
expected: '12.34'
4747
},{
4848
name: 'real/float4',
4949
dataTypeID: 700,

0 commit comments

Comments
 (0)