Re: Weird insert issue

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: Weird insert issue
Дата
Msg-id CAFj8pRDMzvt3N1F2=8Qxab=mzKLU3LAYSDy12pJ3tx1_uJfWBw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Weird insert issue  (Peter Geoghegan <peter.geoghegan86@gmail.com>)
Ответы Re: Weird insert issue  (Larry Meadors <larry.meadors@gmail.com>)
Список pgsql-general


2015-06-28 6:52 GMT+02:00 Peter Geoghegan <peter.geoghegan86@gmail.com>:
On Sat, Jun 27, 2015 at 9:47 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> you can protect it against this issue with locking - in this case you can
> try "for update" clause
>
> http://www.postgresql.org/docs/9.4/static/explicit-locking.html
>
> insert into Favorite (patronId, titleId)
> select 123, 234
> where not exists (
>   select 1 from Favorite where patronId = 123 and titleId = 234 for update
> )

That won't work reliably either -- a SELECT ... FOR UPDATE will still
use an MVCC snapshot. The looping + subxact pattern must be used [1]
if a duplicate violation isn't acceptable. ON CONFLICT DO UPDATE
should be preferred once 9.5 is released.

[1] http://www.postgresql.org/docs/9.4/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE

yes, you have true - cannot to lock, what doesn't exists in pg

Regards

Pavel


 
--
Regards,
Peter Geoghegan

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

Предыдущее
От: Peter Geoghegan
Дата:
Сообщение: Re: Weird insert issue
Следующее
От: Larry Meadors
Дата:
Сообщение: Re: Weird insert issue