Skip to content

column "nan" does not exist #310

Description

@ghazel

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"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions