Re: functions, transactions, key violations

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: functions, transactions, key violations
Дата
Msg-id 6577.1212619512@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: functions, transactions, key violations  (Michael Glaesemann <grzm@seespotcode.net>)
Список pgsql-general
Michael Glaesemann <grzm@seespotcode.net> writes:
> However, my point regarding the example in the docs still holds. Why
> is the exception block necessary? Doesn't wrapping the statements in a
> function ensure the unique_violation couldn't occur?

Well, the point of that example is to deal correctly with the case where
two sessions try to insert the same key concurrently.  The second to
reach the index insertion point will see the conflicting index entry
already there, and it will block until it sees the other transaction
commit or abort, and if commit it will then throw a unique exception.

Are you certain that concurrent executions of purchase() for the same
item_id can never happen in your system?  Because that certainly seems
the most likely explanation from here.

            regards, tom lane

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

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Script errors on run
Следующее
От: Jason Long
Дата:
Сообщение: full vacuum really slows down query