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 1rQFA9-00HWAg-Co for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jan 2024 23:17:37 +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 1rQFA8-00Gbz6-Cg for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jan 2024 23:17:36 +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 1rQFA8-00Gbyy-4a for pgsql-bugs@lists.postgresql.org; Wed, 17 Jan 2024 23:17:36 +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.94.2) (envelope-from ) id 1rQFA5-002N00-Lz for pgsql-bugs@lists.postgresql.org; Wed, 17 Jan 2024 23:17:35 +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 40HNHRqq2082388; Wed, 17 Jan 2024 18:17:27 -0500 From: Tom Lane To: Samuel Dussault cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: Parsing error with begin atomic syntax used in a do block In-reply-to: References: Comments: In-reply-to Samuel Dussault message dated "Wed, 17 Jan 2024 21:18:17 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2082386.1705533447.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 17 Jan 2024 18:17:27 -0500 Message-ID: <2082387.1705533447@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Samuel Dussault writes: > I encounter a problem when creating a procedure using the begin atomic s= yntax in a script encapsulated in a DO block. When executing the DO block,= the parser throws a syntax error. I would expect to be able to create the= procedure with both the new begin atomic and the old syntax. > do > $$ > begin > create or replace procedure test2() > language sql > begin atomic > insert into example (id) values (1); > end; > exception > when others then > rollback; > end > $$; The problem here is that "begin" is a reserved word in plpgsql (and for that matter, so is "end"). I'm not terribly excited about trying to find some kludge that would make this work, because it would almost certainly break other cases. I'd suggest doing the "create procedure" step via EXECUTE, so that you can hide "begin ... end" from the plpgsql parser in a string literal. regards, tom lane