Re: Nested Stored Procedures - ERROR: invalid transaction termination 2D000

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christophe Pettus <xof(at)thebuild(dot)com>
Cc: Kevin Stephenson <kjs714(at)hotmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Nested Stored Procedures - ERROR: invalid transaction termination 2D000
Date: 2025-03-22 14:59:10
Message-ID: 1830668.1742655550@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Christophe Pettus <xof(at)thebuild(dot)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...

regards, tom lane

[1] https://www.postgresql.org/docs/current/dblink.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2025-03-22 15:12:39 Re: query_id: jumble names of temp tables for better pg_stat_statement UX
Previous Message Michael Paquier 2025-03-22 10:32:47 Re: query_id: jumble names of temp tables for better pg_stat_statement UX