column "nan" does not exist
See original GitHub issueUsing 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:
var orm = require('orm');
orm.connect('postgres://user:pass@host/db?debug=true', function (err, db) {
if (err) throw err;
var fun = db.define('fun', {'count': Number});
fun.sync(function (err) {
if (err) throw err;
fun.create([{'count': 'bugz'}], function (err, items) {
if (err) throw err;
console.log(item);
});
});
});
Causes:
(orm/postgres) CREATE TABLE "fun" ("id" SERIAL, "count" REAL, PRIMARY KEY ("id"))
(orm/postgres) INSERT INTO "fun" ("count") VALUES (NaN) RETURNING *
test.js:9
if (err) throw err;
^
error: column "nan" does not exist
at Connection.parseE (pg/lib/connection.js:526:11)
at Connection.parseMessage (pg/lib/connection.js:371:17)
at Socket.<anonymous> (pg/lib/connection.js:86:20)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:736:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
Yes, “bugz” can’t be converted to a number, but the natural PostGres error is much more useful:
# INSERT INTO "fun" ("count") VALUES ('bugz');
ERROR: invalid input syntax for type real: "bugz"
Issue Analytics
- State:
- Created 10 years ago
- Comments:6
Top Results From Across the Web
Node JS API Sequelize PostgreSQL UUID as primary key ...
It returns an error "column Nan does not exist" Initially I was using Integer for the user Id as the primary key, then...
Read more >SQL replication: Unknown column 'NaN' in 'field list'
and does not "Unknown column 'NaN' in 'field list'" indicate that it is. the INSERT INTO and not VALUES that is said to...
Read more >PostgreSQL insert fails if the value is NaN in float type
Inserting NaN value to a PostgrSQL database requires apostrophes around ... "ERROR: column "nan" does not exist LINE 1: EXECUTE qpsqlpstmt_1 ...
Read more >PostgreSQL column does not exist | Definition and Syntax
PostgreSQL column does not exist exception occurs when we have used column did not exist in the table or it will occur when...
Read more >Documentation: 8.2: Numeric Types - PostgreSQL
In addition to ordinary numeric values, the numeric type allows the special value NaN, meaning "not-a-number". Any operation on NaN yields another NaN....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What I mean is, the query orm generates now is:
Instead of:
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.
I’ve got a fix, just gotta fix some tests. Edit: Tests fixed; writing more new tests to prevent regressions…