Re: skip duplicate key error during inserts

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: skip duplicate key error during inserts
Дата
Msg-id b42b73150610200903p59a86a97q8adf73302adc3003@mail.gmail.com
обсуждение исходный текст
Ответ на skip duplicate key error during inserts  (Jean-Christophe Roux <jcxxr@yahoo.com>)
Список pgsql-general
On 10/20/06, Jean-Christophe Roux <jcxxr@yahoo.com> wrote:
> Hello,
> I have a table like this:
> create table dummy (value integer primary key);
> and I insert a row like this
> insert into dummy values(0);
> then I want to insert three rows:
> insert into dummy values(0);
> insert into dummy values(1);
> insert into dummy values(2);

> none of them will be inserted because the first insert is a primary key
> violation. How can I have postgreSQL not mind about the error and proceed to
> the next insert. I could send the inserts one at a time but bundling them
> speeds up the process.
> Thanks

if this is bulk insert,
1. insert into scratch table:
create temp table scratch_foo as select * from foo limit 0;
2. insert into scratch, etc.
3. insert into foo select distinct on * from scratch_foo <-- season to taste

merlin

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: why not kill -9 postmaster
Следующее
От: John Sidney-Woollett
Дата:
Сообщение: Re: Upgrade 7.4 to 8.1 or 8.2?