-
Notifications
You must be signed in to change notification settings - Fork 376
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
column "nan" does not exist #310
Comments
I've added some code to deal with it here. Please try: rm node_modules/sql-query -rf
npm install dresende/node-sql-query and see if that fixes it. |
Why pass 'NaN' instead of the string which was passed in? Maybe postgres knows how to convert whatever it is. |
The code should only affect numbers. If a number is invalid [NaN, Infinity], it gets converted to a string and you get a nice database error. |
What I mean is, the query orm generates now is: INSERT INTO "fun" ("count") VALUES ('NaN') RETURNING * Instead of: INSERT INTO "fun" ("count") VALUES ('bugz') RETURNING * Which actually suppresses the error entirely, storing the postgres NaN value instead of throwing the error like it should. Conceivably I could be passing a string which postgres interprets properly but which orm cannot, exactly like NaN; Infinity and -Infinity are also supported. Also postgres knows what to do with '0xff' while orm doesn't. |
Interestingly, this throws an error as expected: if (err) throw err;
var item = new fun();
item.count = 'bugz';
item.save(function (err) {
if (err) throw err;
console.log(JSON.stringify(item));
db.close();
});
// (orm/postgres) INSERT INTO "fun" ("count") VALUES ('bugz') RETURNING *
// error: invalid input syntax for type real: "bugz"
// at Connection.parseE (/root/projects/node-orm2/node_modules/pg/lib/connection.js:519:11) Something else is casting the value but only in the Edit: You've inadvertantly stumbled onto another bug. I'm looking at it now. |
I've got a fix, just gotta fix some tests. |
Using PostGres, when a value is set which cannot be interpreted as a Number, incorrect SQL is generated which tries to use NaN as a value:
Example:
Causes:
Yes, "bugz" can't be converted to a number, but the natural PostGres error is much more useful:
The text was updated successfully, but these errors were encountered: