Re: can you do rollback in a trigger function?

Поиск
Список
Период
Сортировка
От Shaun Thomas
Тема Re: can you do rollback in a trigger function?
Дата
Msg-id 525D9505.1030209@optionshouse.com
обсуждение исходный текст
Ответ на can you do rollback in a trigger function?  (Quang Thoi <Quang_Thoi@symantec.com>)
Список pgsql-general
On 10/15/2013 01:38 PM, Quang Thoi wrote:

> I want to roll back deletion if there is a reference (FK) in another
> table.
>
> Can I explicitly call a rollback inside a function?

No. Transactions are controlled outside the body of any executing
function. You do have have a couple other options, though. If you can't
use a basic foreign key which does this automatically, you can have your
trigger function return NULL. From the documentation:

"Row-level triggers fired BEFORE can return null to signal the trigger
manager to skip the rest of the operation for this row (i.e., subsequent
triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for
this row)"

You could also raise an explicit error so the user sees something. To
fake a foreign key violation, you'd do:

RAISE EXCEPTION foreign_key_violation;

So you don't need a rollback anyway.

--
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 500 | Chicago IL, 60604
312-676-8870
sthomas@optionshouse.com

______________________________________________

See http://www.peak6.com/email_disclaimer/ for terms and conditions related to this email


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

Предыдущее
От: Vick Khera
Дата:
Сообщение: Re: can you do rollback in a trigger function?
Следующее
От: Carlo Curatolo
Дата:
Сообщение: Re: Invalid Page Header Error