2

I'm trying to learn postgresql's upsert syntax but I keep getting this error:

ERROR:  syntax error at or near "name"
LINE 5:     SET name = EXCLUDED.name;

this is the sql statement:

INSERT INTO users (name, fav_num) 
VALUES ('bob', 2) 
ON CONFLICT (id) DO UPDATE 
SET fav_num = EXCLUDED.fav_num, 
SET name = EXCLUDED.name;

I tried changing the excluded.fav_num and excluded.name to values but I still encounter the same error. I'm running PostgreSQL 10.6. What should be the proper query?

Table:

|------|------|---------|
|  id  | name | fav_num |
|------|------|---------|
|  1   | bob  |    1    |
|------|------|---------|

1 Answer 1

3

It's SET as in:

SET fav_num = EXCLUDED.fav_num, name = EXCLUDED.name

Note one and only one SET.

Sign up to request clarification or add additional context in comments.

3 Comments

From the link below: The action can be: DO NOTHING – means do nothing if the row already exists in the table. DO UPDATE SET column_1 = value_1, .. WHERE condition – update some fields in the table.
It's the same as UPDATE.
Ohh my bad cause most of the example in the internet only has one column so I figured the "..." was another set. It works thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.