brianc / node-pg-types

Type parsing for node-postgres
270 stars 55 forks source link

Postgres outputs non-javascript-compatible JSON #10

Closed SohumB closed 9 years ago

SohumB commented 10 years ago
knex.raw('select row_to_json(row(1111111111111111111::bigint)) as example;')
  .then(function(res) { console.log(res.rows[0].example); });
// outputs { f1: 1111111111111111200 }

That is, postgres doesn't account for javascript's type limits when outputting its json, and node-pg-types can't use its logic for defaulting those types to string, because it just sees that json is coming down the wire. This affects at least bigints and arbitrary-precision numbers, possibly more things.

What do we do? Can we do anything?

brianc commented 10 years ago

I don't think there's anything we can do here. I guess if you want to support huge numerics you'd have to use a custom json parser that would parse big numbers into some kinda module that can represent them. Maybe push the V8 team to add 64bit integer support? :trollface:

bendrucker commented 9 years ago

Yup, no dice here other than using a custom JSON parser