简体   繁体   English

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

[英]Getting postgres error when trying to work with postgres large objects using node.js 'pg'

Trying to execute SELECT lo_creat(?) using pg.Client.query() I'm getting error: 'syntax error at or near ")"'.尝试使用pg.Client.query()执行SELECT lo_creat(?)我收到错误:“在“)”处或附近出现语法错误。

"node" 12.16.1, "pg" 8.0.2, "PostgreSQL" 12.0 “节点”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 thw error here
...

Tried to execute the exact same query on my manual connection via pgAdmin4 and it worked fine returning the created oid .尝试通过 pgAdmin4 在我的手动连接上执行完全相同的查询,并且返回创建的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 ?应该使用$1而不是? . .

await client.query('SELECT lo_creat($1)', [0x00060000]); works correct.工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM