I get errors that look like this from node-postgres (when calling its client.query method):
{ [Error: syntax error at or near "as"]
severity: 'ERROR',
code: '42601',
position: '60',
file: 'scan.l',
line: '1044',
routine: 'scanner_yyerror' } }
If I could see the offending SQL alongside the error message, it would make debugging a lot easier. Is it possible to get it somehow?
I realise that I can implement this manually (wrap client.query etc.), but what I'm interested in is whether node-postgres itself can be coerced into providing the SQL.
Looking at the source code (https://github.com/brianc/node-postgres/blob/master/lib/client.js#L331), the query method returns a Query object. So you should be able to do something like this:
var query = client.query('SELECT $1::int AS number', ['1'], function(err, result) {
if (err) {
var sql = query.text;
}
}
(assuming your callback function is in the same scope as query).
Disclaimer: I've never used node-postgres.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With