-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SELECT COUNT() return typeof string #378
Comments
Getting the same problem with a string being returned for an |
Unfortunately those are going to return strings now since the return type of the It really sucks it introduces such a large backwards compatibility issue, but that's why I bumped the major version. I would suggest if you know you're never going to have more than |
One other thing. If you would like I can produce a module which "reverts" the type parsing changes of v2.x by parsing everything it possibly can parse to numbers. This would be pretty much identical to example: var numberFromPostgres = "1234567890";
var parse = function(stringNumber) {
//check against some length that makes sense
//any whole number of more than 20 digits is likely to
//exceed the maximum number value in javascript
if(stringNumber.length > 20) {
throw new Error('Cannot parse ' + stringNumber + ' to an integer. Sorry about JavaScripts lack of 64bit numbers');
}
return parseInt(stringNumber);
};
parse(numberFromPostgres); Does that make sense? I was planning on doing this in my code base once I upgraded to v2.0 (sometime after nodeconf). |
Damn, that's really unfortunate but the choice makes sense. As for your check, it could simply be var parse = function (str) {
var n = +str;
if (n == str) return n;
throw new Error('Cannot parse ' + str + ' to an integer because it is too big');
}; |
Sweet. Good call. I'll work up this module so I can un-break backwards compatibility as an opt-in module. |
mysql driver had this problem also (people complaining about twitter ids). We added an option. Default was to parse everything as numbers. The few people needing large IDs would activate that option and get every number as string (and would probably use lib BigNumber to work with them). |
@dresende thanks for your help! Yeah making it an option probably would have been a good move. I'm going to work on an add-on module and document how to use it to parse everything as numbers instead of text. |
Hi @brianc, checking in on status of the add on module to parse everything as numbers? (i'm using node-pg-parse-float already, so its really for bigints as returned from functions like count(), as discussed in this issue). thanks for all the good work here! |
I'm in the same boat as spollack. Eager to upgrade to the latest version of pg, but will have to wait until the add-on module is ready. Thanks, @brianc - you've been doing an amazing job on this lib. |
@trevorwilliams thanks. :) Shipping a new minor version now with the feature you're looking for! 🚢 |
Yeah! thanks @brianc. |
Should this be considered closed, then ? |
I think so, yeah. Sometimes I like to leave these kinda issues open as informative. But...github search is a lot better than it used to be so that's probably a waste now. 😄 |
…S ints, node-postgres handles them as strings. Opting-in to handling them as ints because it isn't really a problem here. This makes the event counts be handled in order properly. See brianc/node-postgres#378
using postgres 9.2 and pg moudle 2.0.0
script like following, the count type is number in 1.1.3, but string in 2.0.0, is it by design?
Thanks
Qiang
The text was updated successfully, but these errors were encountered: