| From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> | 
|---|---|
| To: | Barry Kimelman <blkimelman(at)gmail(dot)com> | 
| Cc: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: problem with on conflict / do update using psql 14.4 | 
| Date: | 2022-09-24 17:34:15 | 
| Message-ID: | CAKFQuwbfJUCpFGzpWLp7B5yGcD-3=qbvtGVV4EOu72WR+8tA_g@mail.gmail.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
On Sat, Sep 24, 2022 at 8:49 AM Barry Kimelman <blkimelman(at)gmail(dot)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.
https://www.postgresql.org/docs/current/sql-insert.html
Which seems sufficiently clearly written.
David J.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Adrian Klaver | 2022-09-24 17:35:29 | Re: problem with on conflict / do update using psql 14.4 | 
| Previous Message | Christophe Pettus | 2022-09-24 16:40:23 | Re: problem with on conflict / do update using psql 14.4 |