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 1qdUkl-003dgk-Qt for pgsql-general@arkaria.postgresql.org; Tue, 05 Sep 2023 12:01:55 +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 1qdUkk-001fA3-Jz for pgsql-general@arkaria.postgresql.org; Tue, 05 Sep 2023 12:01:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdUkk-001f9j-8j for pgsql-general@lists.postgresql.org; Tue, 05 Sep 2023 12:01:54 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdUkg-002rMO-9I for pgsql-general@lists.postgresql.org; Tue, 05 Sep 2023 12:01:52 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 6E1CE3200924; Tue, 5 Sep 2023 08:01:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 05 Sep 2023 08:01:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1693915306; x= 1694001706; bh=Xvtos5v3JtBcPYU0EPDAamFWDusbKpmTkPKvW4jrQM0=; b=w gAGjE+ezJeGct4WY1ArvLtmikovZRWHtovG5I450tFVSRAAC1zFWFWdoF2kkYyQx VE1SHKCzPVtpegtZ01oayB3rD8kyGhoWbxVws599joKo/CIuqRArRppKiIw2NO2a U7L5pTTEgTuTECZWwjzJ+n71DBVXKvwDjVnhjk1uwREScAg2lnMhhEQi3pEwbz+W yjExiXBTk1Ind+nnblTQrI4CprpUoGKWPEdFBI1V1zcUvhyaoRftIiiP9beaR/qE PwA7s+f3MoKh6PJTit5FgycJnmf0u2btMYJJ6Va6yspy06vtA23SlCb9/VYd+MOf tRqLTLJkHLYXRpZpcfh6A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehuddgvdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 5 Sep 2023 08:01:45 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 093F1426; Tue, 5 Sep 2023 14:01:44 +0200 (CEST) Date: Tue, 5 Sep 2023 14:01:44 +0200 From: Alvaro Herrera To: Erik Wienhold Cc: "David G. Johnston" , "pgsql-general@lists.postgresql.org" Subject: Re: rollback to savepoint issue Message-ID: <202309051201.hnghlq3bit25@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1165806895.176202.1693840943412@office.mailbox.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-Sep-04, Erik Wienhold wrote: > On 04/09/2023 16:56 CEST David G. Johnston wrote: > > > On Monday, September 4, 2023, Erik Wienhold wrote: > > > > > On 04/09/2023 11:51 CEST Lorusso Domenico wrote: > > > > > > > The original code in embedded in a function, but the problem is the same: > > > > > > Transaction control is not possible in functions. Only in procedures (CALL) > > > and DO blocks. > > > > Then explain why the original savepoint command wasn’t a syntax, or runtime, > > error? > > I don't need to because CREATE {FUNCTION | PROCEDURE} already fails because of > ROLLBACK TO SAVEPOINT. And without a function to execute there can't be any > runtime error because of SAVEPOINT. My point was about transaction control in > plpgsql in general. You can create the function nonetheless if you set check_function_bodies to OFF beforehand. Then it's a "syntax" error detected at runtime. 55432 17devel 1274266=# create function quarrel() returns void language plpgsql as $$ begin savepoint foo; insert into foo default values; rollback to savepoint foo; end $$; ERROR: syntax error at or near "to" LINE 1: ...int foo; insert into foo default values; rollback to savepoi... ^ 55432 17devel 1274266=# set check_function_bodies to 0; SET 55432 17devel 1274266=# create function quarrel() returns void language plpgsql as $$ begin savepoint foo; insert into foo default values; rollback to savepoint foo; end $$; CREATE FUNCTION 55432 17devel 1274266=# select quarrel(); ERROR: syntax error at or near "to" LINE 1: ...int foo; insert into foo default values; rollback to savepoi... ^ QUERY: begin savepoint foo; insert into foo default values; rollback to savepoint foo; end CONTEXT: compilation of PL/pgSQL function "quarrel" near line 1 But it gets worse. If you create a procedure (no longer a function) with a SAVEPOINT and ROLLBACK TO SAVEPOINT, it'll complain about the ROLLBACK TO command, but not about SAVEPOINT; and if you remove that, then it'll fail at runtime saying that SAVEPOINT is unsupported. So it's not super consistent about how it report these various problems. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "El sudor es la mejor cura para un pensamiento enfermo" (Bardia)