Trying to execute SELECT lo_creat(?)
using pg.Client.query()
I'm getting error:
'syntax error at or near ")"'.
"node" 12.16.1, "pg" 8.0.2, "PostgreSQL" 12.0
const { Client } = require('pg');
...
const client = new Client({
host: <host>,
port: <port>,
database: <database>,
user: <user>,
password: <password>,
});
await client.connect();
await client.query("SET SCHEMA '<schema>'"); // everything is fine
await client.query('SELECT lo_creat(?)', [0x00060000]); // throws the error here
...
Tried to execute the exact same query on my manual connection via pgAdmin4 and it worked fine returning the created oid
.
Would appreciate any help, thanks in advance.
The issue here is using wrong syntax to pass the parameters.
$1
should be used instead of ?
.
await client.query('SELECT lo_creat($1)', [0x00060000]);
works correct.