Re: savepoints - Mailing list pgsql-admin

From Alvaro Herrera
Subject Re: savepoints
Date
Msg-id 20060412172947.GF26756@surnet.cl
Whole thread Raw
In response to savepoints  ("Sriram Dandapani" <sdandapani@counterpane.com>)
List pgsql-admin
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.

pgsql-admin by date:

Previous
From: "Sriram Dandapani"
Date:
Subject: savepoints
Next
From: "Sriram Dandapani"
Date:
Subject: WAL file naming after postmaster restart