Lance Pollard
Lance Pollard

Reputation: 79390

Syntax error near "user" PostgreSQL, even though user is quoted

Getting this on postgres:

syntax error at or near ""user""

For the following:

insert into "user" ("id", "email") values ('1', '[email protected]') on conflict do update "user" set "id" = '1', "email" = '[email protected]'

Been playing with it for a while, not sure where the syntax error is. Thank you for your help.

Upvotes: 0

Views: 160

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 247235

Remove the "user" after ON CONFLICT DO UPDATE.

Upvotes: 1

thor
thor

Reputation: 22520

Apparently, you can't specify the table name in the ON CONFLICT UPDATE SET clause. The following seems to work:

insert into "user" ("id", "email") values ('1', '[email protected]')
on conflict do update set "id" = '1', "email" = '[email protected]'

The syntax here:

....
DO UPDATE SET { column_name = { expression | DEFAULT } |
                ( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] ) |
                ( column_name [, ...] ) = ( sub-SELECT )
              } [, ...]
          [ WHERE condition ]

Upvotes: 2

Related Questions