Обсуждение: savepoints

Поиск
Список
Период
Сортировка

savepoints

От
"Sriram Dandapani"
Дата:

This is the scenario:

 

Controller function fncCtrl calls function A, function B and function C in that order.

Function A needs a savepoint to prevent errors from undoing work that needs to be committed regardless of errors in function B or C

 

Is there a way to define a generic savepoint that any errors in B or C will rollback to.

Re: savepoints

От
Alvaro Herrera
Дата:
Sriram Dandapani wrote:
> This is the scenario:
>
>
>
> Controller function fncCtrl calls function A, function B and function C
> in that order.
>
> Function A needs a savepoint to prevent errors from undoing work that
> needs to be committed regardless of errors in function B or C
>
> Is there a way to define a generic savepoint that any errors in B or C
> will rollback to.

What you can do is to have fncCtrl like this:

BEGIN
   perform A();

   BEGIN
     perform B();
     perform C();
   EXCEPTION WHEN ...
     -- here, either B or C failed
   END
END

If B or C fail, the changes made by A will persist.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.