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 1tvukW-0094gP-4G for pgsql-general@arkaria.postgresql.org; Sat, 22 Mar 2025 09:02:36 +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 1tvukS-009IFC-Ul for pgsql-general@arkaria.postgresql.org; Sat, 22 Mar 2025 09:02:32 +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 1tvukS-009IF4-Ju for pgsql-general@lists.postgresql.org; Sat, 22 Mar 2025 09:02:32 +0000 Received: from smtp88.ord1d.emailsrvr.com ([184.106.54.88]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tvukQ-000T8A-15 for pgsql-general@postgresql.org; Sat, 22 Mar 2025 09:02:32 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp20.relay.ord1d.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 5593AC0169; Sat, 22 Mar 2025 05:02:24 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: Nested Stored Procedures - ERROR: invalid transaction termination 2D000 From: Christophe Pettus In-Reply-To: Date: Sat, 22 Mar 2025 09:01:51 +0000 Cc: "pgsql-general@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <12B83964-7B3B-4345-9952-F8FE61727CB5@thebuild.com> References: To: Kevin Stephenson X-Mailer: Apple Mail (2.3776.700.51.11.1) X-Classification-ID: 9890c2cf-d549-480d-9b05-7a6ceefd1281-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, > On Mar 22, 2025, at 08:38, Kevin Stephenson = wrote: > =E2=80=A2 When a top-level stored procedure is called it = implicitly creates a TX if there is no current TX. > =E2=80=A2 When a BEGIN/EXCEPTION block is used it implicitly = creates a subTX for that block. These statements are correct. > =E2=80=A2 When a nested stored procedure is called it implicitly = creates a subTX for that invocation. This one is not. (Although the behavior you are looking for may not = depend on that.) 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.=