Skip to content
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

NULL for numeric fields -> NaN #26

Closed
dvv opened this issue Apr 20, 2011 · 18 comments
Closed

NULL for numeric fields -> NaN #26

dvv opened this issue Apr 20, 2011 · 18 comments

Comments

@dvv
Copy link

dvv commented Apr 20, 2011

Hi!

On the same setup as in https://gist.github.com/929626 :

create table foo(id bigint, num bigint);
insert into foo(id) values(1);

...
db.query('select * from foo').on('row', function(row){
console.log(row); // ---> {id: 1, num: NaN}
});

Can you confirm the issue?

TIA,
--Vladimir

@brianc
Copy link
Owner

brianc commented Apr 20, 2011

I can confirm after work. If this is indeed the case I'll write test & fix the issue tonight.

@dvv
Copy link
Author

dvv commented Apr 20, 2011

I'm GMT+03, what are you (to sync the time window)? Is there a dedicated IRC channel for this project?

@brianc
Copy link
Owner

brianc commented Apr 21, 2011

this passes for me:

test('selecting null integers', function() {
  pg.connect(connectionString, assert.calls(function(err, client) {
    client.query("CREATE TEMP TABLE foo(id bigint, num bigint)");
    client.query("INSERT INTO foo(id) values(1)");
    var q = client.query("SELECT * FROM foo");
    assert.emits(q, 'row', function(row) {
      assert.equal(row.id, 1);
      assert.ok(row.num === null);
    })
  }))
})

@dvv
Copy link
Author

dvv commented Apr 21, 2011

Do you use native? If yes, it's a miracle, since I see in the code the use of plain JS parseInt to convert from DB to JS integers

@dvv
Copy link
Author

dvv commented Apr 21, 2011

Rechecked. Right, for JS client it's null. For native libpq client it's NaN.

@brianc
Copy link
Owner

brianc commented Apr 21, 2011

Yeah...that test was passing under native & pure javascript.

@dvv
Copy link
Author

dvv commented Apr 21, 2011

So you can't reproduce it?

@dvv
Copy link
Author

dvv commented Apr 21, 2011

libpq version-dependent may be...

@brianc
Copy link
Owner

brianc commented Apr 22, 2011

@dvv are you able to run the test suite locally? If you could run that it would be really helpful. If you need help getting the suite set up (it requires a few records to exist in your test database) you can look here or ask on this thread. Maybe there's something particular to your setup the tests could help shake out?

@dvv
Copy link
Author

dvv commented Apr 24, 2011

make test-all passed ok.

@napa3um
Copy link

napa3um commented May 16, 2011

client.query('insert into "table" ("field") values ($1) returning "id";', [null], function(){});

TypeError: Cannot call method 'toString' of undefined

error for native version, ok for js version

@napa3um
Copy link

napa3um commented May 16, 2011

sorry, I tried null and undefined therefore the error doesn't correspond to parameter in an example :)

@brianc
Copy link
Owner

brianc commented May 17, 2011

So...@napa3um your code example is indeed throwing an error or not?

@napa3um
Copy link

napa3um commented May 18, 2011

var pg = require('pg').native;
// var pg = require('pg');

var testArg = null;
// var testArg = 1;

pg.connect("tcp://httpd:374@localhost/node", function(err, client){
if(err) errExit(err);

client.query('select 7 <> $1 as res;', [testArg], function(err, res){
    if(err) errExit(err);

    console.log(res.rows[0].res);
    process.exit();
});

});

function errExit(err){
console.error(err.message);
process.exit(-1);
}


napa3um@hive:~/Workspace/node.js/amedia$ node pg-error.js

/home/napa3um/Workspace/node.js/amedia/node_modules/pg/lib/native.js:201
return val.toString();
^
TypeError: Cannot call method 'toString' of null
at /home/napa3um/Workspace/node.js/amedia/node_modules/pg/lib/native.js:201:18
at Array.map (native)
at [object Object]._translateValues (/home/napa3um/Workspace/node.js/amedia/node_modules/pg/lib/native.js:200:31)
at new (/home/napa3um/Workspace/node.js/amedia/node_modules/pg/lib/native.js:156:8)
at Connection.query (/home/napa3um/Workspace/node.js/amedia/node_modules/pg/lib/native.js:49:11)
at /home/napa3um/Workspace/node.js/amedia/pg-error.js:10:9
at Connection. (/home/napa3um/Workspace/node.js/amedia/node_modules/pg/lib/client-pool.js:87:11)
at Connection.g (events.js:143:14)

@napa3um
Copy link

napa3um commented May 19, 2011

one more problem which isn't present in the js-version:

// var pg = require('pg');
var pg = require('pg').native;

pg.connect("tcp://httpd:374@localhost/node", function(err, client){
if(err) errExit(err);

client.query('select null as res;', function(err, res){
    if(err) errExit(err);

    console.log(res.rows[0].res == null);
    process.exit();
});

});


napa3um@hive:~/Workspace/node.js/amedia$ node pg-error.js
false

@brianc
Copy link
Owner

brianc commented May 19, 2011

Awesome. I've confirmed the issue w/ some unit tests & will work on a patch this evening. Thanks!

brianc added a commit that referenced this issue May 20, 2011
@brianc
Copy link
Owner

brianc commented May 20, 2011

found a fix for this and a few other native related bugs dealing with null values as well....I need to test on various other operating system/postgres combos and then I'll release a new version in npm. thanks again.

@brianc
Copy link
Owner

brianc commented May 20, 2011

Fixed. npm install pg for latest version

@brianc brianc closed this as completed May 20, 2011
brianc pushed a commit that referenced this issue Apr 28, 2020
Add support for TLS parameters in URI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants