Re: problem with on conflict / do update using psql 14.4 - Mailing list pgsql-general

From David G. Johnston
Subject Re: problem with on conflict / do update using psql 14.4
Date
Msg-id CAKFQuwbfJUCpFGzpWLp7B5yGcD-3=qbvtGVV4EOu72WR+8tA_g@mail.gmail.com
Whole thread Raw
In response to Re: problem with on conflict / do update using psql 14.4  (Barry Kimelman <blkimelman@gmail.com>)
List pgsql-general
On Sat, Sep 24, 2022 at 8:49 AM Barry Kimelman <blkimelman@gmail.com> wrote:

I thought the whole point of ON CONFLICT DO UPDATE was so that you could modify the data so that it would be inserted

Nope, the words "DO UPDATE" mean "DO an UPDATE command instead of failing for the CONFLICTing INSERT command".  As mentioned, if you want to ensure you perform an insert of a new record the data you are inserting must not conflict with existing data.  You must do that prior to executing the command.

Or, in the words of the documentation:

The optional ON CONFLICT clause specifies an alternative action to raising a unique violation or exclusion constraint violation error.
...
ON CONFLICT DO UPDATE updates the existing row that conflicts with the row proposed for insertion as its alternative action.


Which seems sufficiently clearly written.

David J.

pgsql-general by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: problem with on conflict / do update using psql 14.4
Next
From: Adrian Klaver
Date:
Subject: Re: problem with on conflict / do update using psql 14.4