2

I am trying to do a PostGRESQL update with Node.js, and I get the following error : source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression

I have been using the same principle for create, read, delete, and I had no issues.

What can be wrong ?

Here is my code :

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)
})
2
  • 2
    Does it help if you remove the unnecessary parentheses? Commented Mar 18, 2018 at 18:35
  • thank you so much for noticing. it works now. it´s so weird cause I used column names with paranthesis in other queries, however I had only one column named in that cases. probably that´s the reason. but still isn´t a logical one. Commented Mar 18, 2018 at 19:18

1 Answer 1

4

The syntax for setting a column value is

name = $1

and not

(name) = ($1)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.