Re: Duplicate key insert question

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Duplicate key insert question
Дата
Msg-id 20030702013636.GN27363@dcc.uchile.cl
обсуждение исходный текст
Ответ на Re: Duplicate key insert question  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
Список pgsql-general
On Wed, Jul 02, 2003 at 10:25:54AM +0900, Jean-Christian Imbeault wrote:
> Reuben D. Budiardja wrote:
> >
> > No, onlu *one* of them will fail, but yes, the other will then generate error.
> > So it really is a trade off. Another way would be to lock the table, as other
> > has suggested. But then there is disadvantages to that also.
>
> Really? I just got a post form Alvaro Herrera saying;
>
> "The solution is not correct in that there _is_ a race condition."
>
> Maybe I misunderstood, but "not correct" doesn't sound good :)

Well, he is right.  One will fail, the other will not.  The race
condition is for the application.  If you want to ignore it, you can do
that, but there _will_ be an ERROR thrown and the transaction will be
aborted.  The other transaction _will_ insert the tuple, though, and it
won't be aborted.

Note that for the race condition to show there has to be a race, i.e.
two backends trying to insert the same primary key at the same time.  If
one finishes half a second before the other, they will behave that way
you want, i.e. there will one tuple inserted and no error generated.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"No deja de ser humillante para una persona de ingenio saber
que no hay tonto que no le pueda enseñar algo." (Jean B. Say)

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

Предыдущее
От: Chris Albertson
Дата:
Сообщение: Re: PSQL NEWBIE - RUNTIME ERROR
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: Duplicate key insert question