pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Samuel Dussault <Samuel.Dussault@USherbrooke.ca>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Parsing error with begin atomic syntax used in a do block
Date: Wed, 17 Jan 2024 18:17:27 -0500
Message-ID: <2082387.1705533447@sss.pgh.pa.us> (raw)
In-Reply-To: <YT2PR01MB88552C3E9AD40A6C038774A781722@YT2PR01MB8855.CANPRD01.PROD.OUTLOOK.COM>
References: <YT2PR01MB88552C3E9AD40A6C038774A781722@YT2PR01MB8855.CANPRD01.PROD.OUTLOOK.COM>

Samuel Dussault <Samuel.Dussault@USherbrooke.ca> writes:
> I encounter a problem when creating a procedure using the begin atomic syntax 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





view thread (3+ messages)  latest in thread

Message-ID: <2082387.1705533447@sss.pgh.pa.us>
Permalink:  ../2082387.1705533447@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2082387.1705533447@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, Samuel.Dussault@USherbrooke.ca, pgsql-bugs@lists.postgresql.org
  Subject: Re: Parsing error with begin atomic syntax used in a do block
  In-Reply-To: <2082387.1705533447@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox