Re: [GENERAL] INSERT and ON CONFLICT

Поиск
Список
Период
Сортировка
От Brian Dunavant
Тема Re: [GENERAL] INSERT and ON CONFLICT
Дата
Msg-id CAJTy2eki6NRxCLiN-wPFyfm1fwmHEPfpWXjtCOx8AXHF8y6-2Q@mail.gmail.com
обсуждение исходный текст
Ответ на [GENERAL] INSERT and ON CONFLICT  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: [GENERAL] INSERT and ON CONFLICT  (Rich Shepard <rshepard@appl-ecosys.com>)
Список pgsql-general
I believe the following test should answer your question.

db=# create table test ( a integer not null unique );
CREATE TABLE

db=# insert into test values (1);
INSERT 0 1

db=# insert into test values (1);
ERROR:  duplicate key value violates unique constraint "test_a_key"
DETAIL:  Key (a)=(1) already exists.

db=# insert into test values (1) on conflict do nothing;
INSERT 0 0



On Fri, Mar 10, 2017 at 12:35 PM, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>   I'm filling a table with rows and have the first batch successfully
> inserted. When I add more rows there may be some that already exist in the
> table and I would prefer that they be ignored and the insert process
> continue.
>
>   The syntax page for INSERT suggests that ON CONFLICT DO NOTHING is exactly
> what I want to include in the command. Have I correctly interpreted what the
> DO NOTHING option does when a row to be inserted already is present in the
> table?
>
> Rich
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [GENERAL] Upgradede -9.6.1 to -9.6.2; postmaster will not start
Следующее
От: Rich Shepard
Дата:
Сообщение: Re: [GENERAL] Upgradede -9.6.1 to -9.6.2; postmaster will notstart