brianc/node-postgres — pull request #353 by sevastos (2013-05-20 01:19:03+00:00)
Title: Handle bigint as string to prevent precision loss

TIL dealing with bigints in javascript is a bit of a pain.

I had a weird issue of inserting correctly bigints on the db but getting off by a bit numbers on the response.

Apparently all the numbers in javascript are floating-point numbers[1] and the accuracy is only assured for integers ±253 between -9007199254740992 and 9007199254740992.
However bigint ranges ±263: -9223372036854775808 to 9223372036854775807 [2].

The most common solution for handling bigint data on javascript is carry them with strings and use special libs for math operations. So strings it is.

However, I wonder if it may cause any troubles to anyone that is treating bigint as number on javascript-level and do some checks around that. Though they shouldn't since that only works till the ±253 range and is not the right way.

Anyway let me know what you think.
Thanks

[1]: http://www.irt.org/script/1031.htm
[2]: http://www.postgresql.org/docs/9.2/static/datatype-numeric.html