【发布时间】:2021-05-30 00:19:56
【问题描述】:
如何在 Nodejs 中使用参数化查询返回结果?
如果我删除RETURNING*,查询运行良好
现在,服务器返回此错误
错误:“返回”处或附近的语法错误
server.js
const text = "UPDATE users SET info = JSONB_SET(info, '{geometry,coordinates}', '"+coords+"') WHERE id=$1 RETURNING*";
const values = [id];
pool.query(text, values, (err, res) => {
if (err) {
//log errors
console.log(err.stack);
//return error to client
} else {
//success
//console.log(res.rows);
}
});
【问题讨论】:
-
*和RETURNING之间不应该有空格吗? -
@norie : 不,这不会影响查询
-
我见过的所有使用
RETURNING的查询在RETURNING之后都有一个空格,后跟*以返回所有字段或要返回的字段列表。如果后面没有空格,则会被视为RETURNING*。 -
@norie :相信我,我试过了。我挠头
标签: node.js postgresql syntax-error node-postgres