question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

column "nan" does not exist

See original GitHub issue

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:


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:closed
  • Created 10 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
ghazelcommented, Aug 23, 2013

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.

0reactions
dxgcommented, Aug 27, 2013

I’ve got a fix, just gotta fix some tests. Edit: Tests fixed; writing more new tests to prevent regressions…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found