0

sql err: 'pq: syntax error at or near "WHERE"', sql: 'INSERT INTO table (id,user,type) VALUES ($1,$2,$3) ON CONFLICT WHERE id = $4 AND user = $5 DO UPDATE SET type = $6', params: [3 158 up 3 158 up]

Using the info on this page, I thought I could chain together an INSERT statement with an ON CONFLICT clause such that if user and id were found in the same row of the table, update that row instead. Where is the syntax error mentioned above?

Gabe Spound
  • 568
  • 5
  • 28
  • A lone `WHERE` clause as the *`conflict_target`* is NOT allowed. The *`conflict_target`*, when not using the `ON CONSTRAINT constraint_name` variant, MUST consist of one or more *`index_column_name`* columns and/or *`index_expression`* expressions, and an optional *`index_predicate`*. – mkopriva Sep 09 '21 at 02:50
  • Show the table definition including all its indexes/constraints so we can see and suggest what would be a valid candidate for the *`conflict_target`*. – mkopriva Sep 09 '21 at 02:53

0 Answers0