Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux