Closed sibedge closed 7 years ago
Can you include a sample of code that produces the issue? I can't help without seeing some code that's causing a problem. You're likely passing something other than an array as the values object to client.query('foo', ['bar'])
but all I can do is guess w/o seeing what is causing the issue.
@brianc you were right, it has to do with passing in a value instead of an array.
But consider the following code:
var pg = require('pg');//.native;
var pool = new pg.Pool(cn);
pool.connect((err, client, done) => {
if (err) {
console.log('ERROR:', err);
return;
}
client.query('select * from findUser(1)', 1, (err, result) => {
if (err) {
console.log('ERROR:', err);
} else {
console.log('DATA:', result.rows);
}
done();
});
});
It works with the JavaScript bindings, as it happily ignores the parameters that are not needed, but just as we uncomment the .native
part there, we get that error I reported earlier.
So there, at least, a discrepancy in how the driver handles it in the Native Bindings.
Thanks for pointing that out! Yeah the JavaScript bindings should probably be brought up to throw an error or have the query error out if you pass anything other than an array as the value to the values
parameter. Silent ignore/failure of invalid method args kinda gross, I think. What do you think?
For someone who tried to switch from JavaScript to the Native bindings and got stuck with some existing tests, I'd say consistency is the most valuable aspect here :smile:
👍 I hear ya. I'll make it throw a friendly error in both native & pure JS if you don't pass an array for values. 😄
this will be fixed in pg7.0 - both native and js driver will have the query callback with an error if you pass anything other than an array as the values argument to a parameterized query.
https://github.com/brianc/node-postgres/pull/1366
Thanks for your patience!
I keep getting the following error in my tests after upgrading to the latest branch 6.3.0 of the main driver:
Previously all tests were running against v5.1 of the driver, plus the latest pg-native, and the error never occurred.