pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jiangshan.liu@tju.edu.cn
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
Date: Wed, 20 Mar 2024 17:02:06 -0400
Message-ID: <103434.1710968526@sss.pgh.pa.us> (raw)
In-Reply-To: <18403-7069fc75f5255783@postgresql.org>
References: <18403-7069fc75f5255783@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> I have approximated the program to a clean situation. When I execute this
> program, the PL/pgSQL engine does not report errors to me:

> DO $$
> DECLARE
> DECLARE
>     var1 INT = 1;
> BEGIN
>     RAISE NOTICE '%', var1;
> END;
> $$;

That is not valid code according to the documentation, which clearly
says that every DECLARE must be followed by BEGIN and then END [1].
You happen to get away with it because of an undocumented "feature":
one of the options for a declaration statement is

                | K_DECLARE
                    {
                        /* We allow useless extra DECLAREs */
                    }

So the first DECLARE begins the block, and the second is an
ignored noise word.

> DO $$
> DECLARE
> <<label>>
> DECLARE
>     var1 INT = 1;
> BEGIN
>     RAISE NOTICE '%', var1;
> END;
> $$;

This, however, is flat wrong, and the error message seems
perfectly on-point to me:

> ERROR:  block label must be placed before DECLARE, not after
> LINE 3: <<label>>
>         ^

			regards, tom lane

[1] https://www.postgresql.org/docs/current/plpgsql-structure.html





view thread (5+ messages)

Message-ID: <103434.1710968526@sss.pgh.pa.us>
Permalink:  ../103434.1710968526@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/103434.1710968526@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, jiangshan.liu@tju.edu.cn, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
  In-Reply-To: <103434.1710968526@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