Re: Functions, savepoints, autocommit = I am confused !

From: <Holger(dot)Friedrich-Fa-Trivadis(at)it(dot)nrw(dot)de>
To: <randomdev4+postgres(at)gmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Functions, savepoints, autocommit = I am confused !
Date: 2015-06-26 15:53:10
Message-ID: C5DBACC6DCC7604C9E4875FD9C7968B11A14E0E531@ITXS01EVS.service.it.nrw.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tim Smith wrote on Friday, June 26, 2015 5:38 PM:
> ERROR: cannot begin/end transactions in PL/pgSQL
> HINT: Use a BEGIN block with an EXCEPTION clause instead.
> CONTEXT: PL/pgSQL function
> app_security.validatesession(app_domains.app_uuid,inet,text,bigint,bigint)
> line 16 at SQL statement

> Line 16 to which it refers is "ROLLBACK TO SAVEPOINT"

I believe I've read you can have nested BEGIN ... END blocks, and the transaction control is done implicitly by the PL/pgSQL exception handling, so you probably can write

BEGIN
...
BEGIN
...
EXCEPTION
WHEN OTHERS THEN
...
END
END;

which would (hopefully) only roll back the second ... not the first ... (not sure if you still need to declare the savepoint, at least, as you found out, explicitly rolling back to the savepoint is not allowed in PL/pgSQL). Note that the third ... probably should not raise or re-raise an exception, otherwise you have an exception in the outer BEGIN-END block and everything is rolled back.

Best regards
Holger Friedrich

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2015-06-26 15:56:21 Re: Functions, savepoints, autocommit = I am confused !
Previous Message Tim Smith 2015-06-26 15:38:26 Re: Functions, savepoints, autocommit = I am confused !