我正在尝试使用PostGRESQL
进行update
Node.js
,并获得以下error : source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression
我一直对principle
使用相同的create, read, delete,
,我没有任何问题。
有什么不对?
这是我的代码:
var pg = require("pg")
var pgClient = new pg.Client({
host: 'localhost',
database: 'tutorial',
user: 'postgres',
password: 'password',
port: 5432,
})
pgClient.connect(err => {
if (err) {
console.log('Could not connect to postgres:', err)
process.exit()
}
console.log("Connected to postgres");
});
var aParams = ["Jenny", 1]
var sQuery = 'UPDATE public.users SET (name) = ($1) WHERE (id) = ($2)';
pgClient.query(sQuery, aParams, (err, res) => {
if (err) {
console.log(err)
process.exit()
}
console.log(res.rows)
})
答案 0 :(得分:1)
设置列值的语法是
name = $1
而不是
(name) = ($1)