Christophe and Tom, thank you for your responses, but I'm still a bit confused. In my original email, the Test 2 case is allowing a ROLLBACK in the EXCEPTION clause without throwing an error. Is it a NOP ROLLBACK being applied to an aborted subTX, a real full ROLLBACK, or something else? Please advise.
Thanks,
Kevin Stephenson
From: Tom Lane <tgl@sss.pgh.pa.us> Sent: Saturday, March 22, 2025 7:59 AM To: Christophe Pettus <xof@thebuild.com> Cc: Kevin Stephenson <kjs714@hotmail.com>; pgsql-general@postgresql.org <pgsql-general@postgresql.org> Subject: Re: Nested Stored Procedures - ERROR: invalid transaction termination 2D000
Christophe Pettus <xof@thebuild.com> writes: > A procedure cannot issue top-level transaction control statements from within an exception block, and attempting to do so raises the error you saw. This includes procedures that are called from within an exception block.
Yeah. Postgres doesn't have autonomous transactions (not yet anyway), and you can't fake them like that.
A way that does work, I believe, is to set up a second session with dblink[1] and use that to issue the autonomous transaction. Ugly and inefficient for sure, but if you've gotta have it...