Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tw0Ji-009pgC-LF for pgsql-general@arkaria.postgresql.org; Sat, 22 Mar 2025 14:59:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tw0Jf-00EfAL-Hs for pgsql-general@arkaria.postgresql.org; Sat, 22 Mar 2025 14:59:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tw0Jf-00EfAD-7R for pgsql-general@lists.postgresql.org; Sat, 22 Mar 2025 14:59:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tw0Jc-000WBT-1s for pgsql-general@postgresql.org; Sat, 22 Mar 2025 14:59:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 52MExAEg1830669; Sat, 22 Mar 2025 10:59:10 -0400 From: Tom Lane To: Christophe Pettus cc: Kevin Stephenson , "pgsql-general@postgresql.org" Subject: Re: Nested Stored Procedures - ERROR: invalid transaction termination 2D000 In-reply-to: <12B83964-7B3B-4345-9952-F8FE61727CB5@thebuild.com> References: <12B83964-7B3B-4345-9952-F8FE61727CB5@thebuild.com> Comments: In-reply-to Christophe Pettus message dated "Sat, 22 Mar 2025 09:01:51 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1830667.1742655550.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 22 Mar 2025 10:59:10 -0400 Message-ID: <1830668.1742655550@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Christophe Pettus writes: > A procedure cannot issue top-level transaction control statements from w= ithin 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