Re: Conditional INSERT: if not exists

Поиск
Список
Период
Сортировка
От Stuart Bishop
Тема Re: Conditional INSERT: if not exists
Дата
Msg-id 4524AF19.2040206@stuartbishop.net
обсуждение исходный текст
Ответ на Re: Conditional INSERT: if not exists  ("Don Morrison" <donmorrison@gmail.com>)
Список pgsql-novice
Don Morrison wrote:

> My problem: if the insert fails because the value already exists, then
> this starts a rollback of my entire transaction.  The solution I'm
> trying is to create a nested transaction with a savepoint right before
> the insert, thus catching the rollback with the nested
> transaction...I'm not sure the nested transaction is necessary...maybe
> just the savepoint. Example:

You need to:

SAVEPOINT insert_may_fail
try:
    INSERT INTO ...
    RELEASE SAVEPOINT
except:
    ROLLBACK TO SAVEPOINT
    UPDATE ...

You can catch the exception either in Python, or if you are using a ZSQL
method, using <dtml-try>.


--
Stuart Bishop <stuart@stuartbishop.net>
http://www.stuartbishop.net/


Вложения

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Interface of the R-tree in order to work with postgresql
Следующее
От: "Andreas Andreakis"
Дата:
Сообщение: problems with left outer join