postgresql 尝试使用node.js 'pg'处理postgres大型对象时出现postgres错误

gk7wooem  于 2023-06-22  发布在  PostgreSQL
关注(0)|答案(1)|浏览(117)

尝试使用pg.Client.query()执行SELECT lo_creat(?)时出现错误:'语法错误位于或接近')'。
“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
...

尝试通过pgAdmin4在我的手动连接上执行完全相同的查询,它工作正常,返回创建的oid
会很感激任何帮助,提前感谢。

e4eetjau

e4eetjau1#

这里的问题是使用了错误的语法来传递参数。
应该使用$1而不是?
await client.query('SELECT lo_creat($1)', [0x00060000]);工作正常。

相关问题