{"action":"created","issue":{"url":"https://api.github.com/repos/brianc/node-postgres/issues/353","repository_url":"https://api.github.com/repos/brianc/node-postgres","labels_url":"https://api.github.com/repos/brianc/node-postgres/issues/353/labels{/name}","comments_url":"https://api.github.com/repos/brianc/node-postgres/issues/353/comments","events_url":"https://api.github.com/repos/brianc/node-postgres/issues/353/events","html_url":"https://github.com/brianc/node-postgres/pull/353","id":14504255,"number":353,"title":"Handle bigint as string to prevent precision loss","user":{"login":"sevastos","id":620714,"avatar_url":"https://avatars2.githubusercontent.com/u/620714?v=3","gravatar_id":"","url":"https://api.github.com/users/sevastos","html_url":"https://github.com/sevastos","followers_url":"https://api.github.com/users/sevastos/followers","following_url":"https://api.github.com/users/sevastos/following{/other_user}","gists_url":"https://api.github.com/users/sevastos/gists{/gist_id}","starred_url":"https://api.github.com/users/sevastos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sevastos/subscriptions","organizations_url":"https://api.github.com/users/sevastos/orgs","repos_url":"https://api.github.com/users/sevastos/repos","events_url":"https://api.github.com/users/sevastos/events{/privacy}","received_events_url":"https://api.github.com/users/sevastos/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2013-05-20T01:19:03Z","updated_at":"2017-03-02T09:21:33Z","closed_at":"2013-06-19T02:21:43Z","pull_request":{"url":"https://api.github.com/repos/brianc/node-postgres/pulls/353","html_url":"https://github.com/brianc/node-postgres/pull/353","diff_url":"https://github.com/brianc/node-postgres/pull/353.diff","patch_url":"https://github.com/brianc/node-postgres/pull/353.patch"},"body":"TIL dealing with bigints in javascript is a bit of a pain.\n\nI had a weird issue of inserting correctly bigints on the db but getting off by a bit numbers on the response.\n\nApparently all the numbers in javascript are floating-point numbers<sup>[1](http://www.irt.org/script/1031.htm)</sup> and the accuracy is only assured for integers ±2<sup>53</sup> between -9007199254740992 and 9007199254740992. \nHowever bigint ranges ±2<sup>63</sup>: -9223372036854775808 to 9223372036854775807 <sup>[2](http://www.postgresql.org/docs/9.2/static/datatype-numeric.html)</sup>.\n\nThe 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.\n\nHowever, 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 ±2<sup>53</sup> range and is not the right way.\n\nAnyway let me know what you think.\nThanks\n"},"comment":{"url":"https://api.github.com/repos/brianc/node-postgres/issues/comments/283600366","html_url":"https://github.com/brianc/node-postgres/pull/353#issuecomment-283600366","issue_url":"https://api.github.com/repos/brianc/node-postgres/issues/353","id":283600366,"user":{"login":"eric-brechemier","id":151276,"avatar_url":"https://avatars2.githubusercontent.com/u/151276?v=3","gravatar_id":"","url":"https://api.github.com/users/eric-brechemier","html_url":"https://github.com/eric-brechemier","followers_url":"https://api.github.com/users/eric-brechemier/followers","following_url":"https://api.github.com/users/eric-brechemier/following{/other_user}","gists_url":"https://api.github.com/users/eric-brechemier/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-brechemier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-brechemier/subscriptions","organizations_url":"https://api.github.com/users/eric-brechemier/orgs","repos_url":"https://api.github.com/users/eric-brechemier/repos","events_url":"https://api.github.com/users/eric-brechemier/events{/privacy}","received_events_url":"https://api.github.com/users/eric-brechemier/received_events","type":"User","site_admin":false},"created_at":"2017-03-02T09:21:33Z","updated_at":"2017-03-02T09:21:33Z","body":"> Apparently all the numbers in javascript are floating-point numbers1 and the accuracy is only assured for integers ±2<sup>53</sup> between -9007199254740992 and 9007199254740992.\r\nHowever bigint ranges ±2<sup>63</sup>: -9223372036854775808 to 9223372036854775807 2.\r\n>\r\n> 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.\r\n\r\nWhy not keep BIGINT values as numbers up to ±2<sup>53</sup>, and only use strings for values between ±2<sup>53</sup> and ±2<sup>63</sup>?\r\n\r\nThis would be less confusing in most cases, and only confusing when truly required."}}
{"actor":{"display_login":"eric-brechemier"}}