-
Notifications
You must be signed in to change notification settings - Fork 55
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(*) as c from users returns type "string" #39
Comments
This is not a bug. Take a look at the postgres docs on the types of the aggregate functions: http://www.postgresql.org/docs/9.4/static/functions-aggregate.html You'll see that count is a bigint. node-postgres can't auto-parse that for you without loss of precision. If you know that your counts are small enough, you can safely parse it in your application code. |
This issue appeared overnight and created failing comparisons like Now I am stuck trying to figure out if a postgres update caused this behavior, or some hidden node-pg update, or.. ? |
No idea what changed in your setup but this has been the behavior in node-postgres for a long time, well over a year if memory serves. |
Okay, thanks for the clarification. This lets me rule out a change in the node-pg modules. I still cannot wrap my head around this issue. |
First of all thanks for this nice project. I am experiencing an issue where I use
count(*)
in a query and I get the value "2" returned, which is represented as a Javascript string.An explicit typecast fixes the problem, but I am afraid that many more of these bugs might occur in the project. As this issue came up overnight, I am unsure where to search the culprit of this problem.
I have written test cases using db.connect -> db.query -> typeof result.rows[0].c === "number", and found out that only count(*) raises this issue. I am using
pg
version 4.4.1.The text was updated successfully, but these errors were encountered: