Re: Solution to UPDATE...INSERT problem

Поиск
Список
Период
Сортировка
Искать
От
Tom Lane
Тема
Re: Solution to UPDATE...INSERT problem
Дата
Msg-id
9529.1048747289@sss.pgh.pa.us
Ответ на
Solution to UPDATE...INSERT problem (Christopher Kings-Lynne)
Список
Дерево обсуждения
Solution to UPDATE...INSERT problem "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Re: [GENERAL] Solution to UPDATE...INSERT problem Lincoln Yeoh <lyeoh@pop.jaring.my>
Re: Solution to UPDATE...INSERT problem Tom Lane <tgl@sss.pgh.pa.us>
Re: Solution to UPDATE...INSERT problem Haroldo Stenger <hstenger@adinet.com.uy>
"Christopher Kings-Lynne"  writes:
> INSERT INTO table SELECT 1, 'foo' EXCEPT SELECT 1, 'foo' FROM table WHERE
> pkcol=1;

> See? So now that INSERT statement will insert the row if it doesn't exist,
> or insert zero rows if it does.  You are then guaranteed that your
> transaction will not fail and rollback, so you can repeat your update, or do
> the insert first and then the update, etc.

Uh, why exactly do you think this is race-free?

It looks fancy, but AFAICS the SELECT will return info that is correct
as of its starting timestamp; which is not enough to guarantee that the
INSERT won't conflict with another transaction doing the same thing
concurrently.

			regards, tom lane

В списке pgsql-hackers по дате отправления
От: Thomas T. Thai
Дата:
От: Christopher Kings-Lynne
Дата:
FAQ