Re: Duplicate key insert question

Поиск
Список
Период
Сортировка
От Jean-Christian Imbeault
Тема Re: Duplicate key insert question
Дата
Msg-id 3F022B23.9030202@mega-bucks.co.jp
обсуждение исходный текст
Ответ на Duplicate key insert question  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
Ответы Re: Duplicate key insert question  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Re: Duplicate key insert question  ("Reuben D. Budiardja" <techlist@voyager.phys.utk.edu>)
Список pgsql-general
Reuben D. Budiardja wrote:
>
> Hi, not sure if this is answering your question, but I just asked similar
> questions here. I asked about using INSERT WHERE NOT EXISTS (which you can do
> in PostgreSQL). Here is what you can do:
>
> INSERT INTO mytable
> SELECT 'value1', 'value2'
>    WHERE NOT EXISTS
>         (SELECT NULL FROM mytable
>                 WHERE mycondition)
>
> http://marc.theaimsgroup.com/?l=postgresql-general&w=2&r=1&s=WHERE+NOT+EXISTS&q=b

Thanks for the link!

I read the thread and it looks like even the above solution is not
perfect because of a possible race condition where two inserts trying to
insert a row with a pk not in the table will both get think it is ok to
do so, try it and then both will fail?

If I followed all the arguments correctly according to the thread there
is *no* way to do what I (and you ;) want in one simple query.

Do you agree? Or did I miss something?

Jean-Christian Imbeault


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

Предыдущее
От: "Maksim Likharev"
Дата:
Сообщение: Re: Duplicate key insert question
Следующее
От: Chris Albertson
Дата:
Сообщение: Re: ERROR: language "c" is not trusted