Re: Transactions within a function body - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Transactions within a function body
Date
Msg-id 20081002003442.GG3878@alvh.no-ip.org
Whole thread Raw
In response to Re: Transactions within a function body  ("Dennis Brakhane" <brakhane@googlemail.com>)
Responses Re: Transactions within a function body  ("Albe Laurenz" <laurenz.albe@wien.gv.at>)
List pgsql-general
Dennis Brakhane escribió:
> On Wed, Oct 1, 2008 at 5:54 PM, Reg Me Please <regmeplease@gmail.com> wrote:
> > Hi all.
> >
> > Is there a way to have (sub)transactions within a function body?
> > I'd like to execute some code (a transaction!) inside a function and later
> > decide whether that transaction is to be committed or not.
>
> You could issue a "SAVEPOINT name". If at the end you don't want your
> changes to apply, you can issue a "ROLLBACK to name"

Actually you can't use SAVEPOINT nor ROLLBACK TO within a function.  In
PL/pgSQL you can use EXCEPTION blocks (if you don't like the changes,
just do a RAISE EXCEPTION, and the exception block is run).

--
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

pgsql-general by date:

Previous
From: "Harvey, Allan AC"
Date:
Subject: Re: inserting only new rows from csv file
Next
From: "Darragh Gammell"
Date:
Subject: Re: tsearch2 Upgrade to 8.3 tsearch2.so errors