Re: problem with on conflict / do update using psql 14.4

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: problem with on conflict / do update using psql 14.4
Дата
Msg-id CAKFQuwbfJUCpFGzpWLp7B5yGcD-3=qbvtGVV4EOu72WR+8tA_g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: problem with on conflict / do update using psql 14.4  (Barry Kimelman <blkimelman@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Christophe Pettus
Дата:
Сообщение: Re: problem with on conflict / do update using psql 14.4
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: problem with on conflict / do update using psql 14.4