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 1tw7kI-00Avhp-AH for pgsql-general@arkaria.postgresql.org; Sat, 22 Mar 2025 22:55:14 +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 1tw7kG-0048E2-UY for pgsql-general@arkaria.postgresql.org; Sat, 22 Mar 2025 22:55:12 +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 1tw7kG-0048Dt-K0 for pgsql-general@lists.postgresql.org; Sat, 22 Mar 2025 22:55:12 +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 1tw7kE-000ZlO-1Q for pgsql-general@postgresql.org; Sat, 22 Mar 2025 22:55:12 +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 52MMt82w442119; Sat, 22 Mar 2025 18:55:08 -0400 From: Tom Lane To: Kevin Stephenson cc: Christophe Pettus , "pgsql-general@postgresql.org" Subject: Re: Nested Stored Procedures - ERROR: invalid transaction termination 2D000 In-reply-to: References: <12B83964-7B3B-4345-9952-F8FE61727CB5@thebuild.com> <1830668.1742655550@sss.pgh.pa.us> Comments: In-reply-to Kevin Stephenson message dated "Sat, 22 Mar 2025 21:37:53 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <442117.1742684108.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 22 Mar 2025 18:55:08 -0400 Message-ID: <442118.1742684108@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Kevin Stephenson writes: > Christophe and Tom, thank you for your responses, but I'm still a bit co= nfused. In my original email, the Test 2 case is allowing a ROLLBACK in th= e EXCEPTION clause without throwing an error. Is it a NOP ROLLBACK being a= pplied to an aborted subTX, a real full ROLLBACK, or something else? Pleas= e advise. The sub-transaction only exists for the body of the BEGIN construct, up until EXCEPTION. By the time control arrives at an exception handler, we've rolled back the sub-xact and are executing in the outer transaction again. So if that's a top-level transaction, you can roll it back, but if it's a subtransaction you can't. regards, tom lane