pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
5+ messages / 4 participants
[nested] [flat]
* BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
@ 2024-03-20 19:35 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 3 replies; 5+ messages in thread
From: PG Bug reporting form @ 2024-03-20 19:35 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: jiangshan.liu@tju.edu.cn
The following bug has been logged on the website:
Bug reference: 18403
Logged by: Jiangshan Liu
Email address: jiangshan.liu@tju.edu.cn
PostgreSQL version: 15.2
Operating system: Ubuntu
Description:
Hi, I think PL/pgSQL is reporting unexpected errors when dealing with
DECLARE blocks paired with <<label>>.
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;
$$;
But when I try to add <<label>> before the second DECLARE block, the
PL/pgSQL engine prompts me with this error message:
DO $$
DECLARE
<<label>>
DECLARE
var1 INT = 1;
BEGIN
RAISE NOTICE '%', var1;
END;
$$;
> ERROR: block label must be placed before DECLARE, not after
LINE 3: <<label>>
^
It seems to think that I am adding <<label>> after the first DECLARE block,
which is not my intention. I do add the <<label>> before the second DECLARE
block. Why is this program being reported as an error? Is this a bug in
PL/pgSQL's handling of <<label>>?
Looking forward and thank you for your response to this question.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
@ 2024-03-20 20:37 Pavel Stehule <pavel.stehule@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
2 siblings, 0 replies; 5+ messages in thread
From: Pavel Stehule @ 2024-03-20 20:37 UTC (permalink / raw)
To: jiangshan.liu@tju.edu.cn; pgsql-bugs@lists.postgresql.org
st 20. 3. 2024 v 20:59 odesÃlatel PG Bug reporting form <
noreply@postgresql.org> napsal:
> The following bug has been logged on the website:
>
> Bug reference: 18403
> Logged by: Jiangshan Liu
> Email address: jiangshan.liu@tju.edu.cn
> PostgreSQL version: 15.2
> Operating system: Ubuntu
> Description:
>
> Hi, I think PL/pgSQL is reporting unexpected errors when dealing with
> DECLARE blocks paired with <<label>>.
> 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;
> $$;
>
> But when I try to add <<label>> before the second DECLARE block, the
> PL/pgSQL engine prompts me with this error message:
>
> DO $$
> DECLARE
> <<label>>
> DECLARE
> var1 INT = 1;
> BEGIN
> RAISE NOTICE '%', var1;
> END;
> $$;
>
> > ERROR: block label must be placed before DECLARE, not after
> LINE 3: <<label>>
> ^
>
> It seems to think that I am adding <<label>> after the first DECLARE block,
> which is not my intention. I do add the <<label>> before the second DECLARE
> block. Why is this program being reported as an error? Is this a bug in
> PL/pgSQL's handling of <<label>>?
>
> Looking forward and thank you for your response to this question.
>
There cannot be labels between DECLARE keywords. The label in this case is
not related to DECLARE, but to the following BEGIN END block.
Regards
Pavel
^ permalink raw reply [nested|flat] 5+ messages in thread
* BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
@ 2024-03-20 20:47 David G. Johnston <david.g.johnston@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
2 siblings, 1 reply; 5+ messages in thread
From: David G. Johnston @ 2024-03-20 20:47 UTC (permalink / raw)
To: jiangshan.liu@tju.edu.cn <jiangshan.liu@tju.edu.cn>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
On Wednesday, March 20, 2024, PG Bug reporting form <noreply@postgresql.org>
wrote:
> The following bug has been logged on the website:
>
> Bug reference: 18403
> Logged by: Jiangshan Liu
> Email address: jiangshan.liu@tju.edu.cn
> PostgreSQL version: 15.2
> Operating system: Ubuntu
> Description:
>
> Hi, I think PL/pgSQL is reporting unexpected errors when dealing with
> DECLARE blocks paired with <<label>>.
> 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;
> $$;
The failure to report an error here seems contrary to the documentation.
When the end of the DO text is reached and only a single begin/end pair is
seen the parser is being loose in being OK that one of the declares was not
associated with a full block.
David J.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
@ 2024-03-20 20:57 Pavel Stehule <pavel.stehule@gmail.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Pavel Stehule @ 2024-03-20 20:57 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: jiangshan.liu@tju.edu.cn <jiangshan.liu@tju.edu.cn>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
st 20. 3. 2024 v 21:47 odesÃlatel David G. Johnston <
david.g.johnston@gmail.com> napsal:
> On Wednesday, March 20, 2024, PG Bug reporting form <
> noreply@postgresql.org> wrote:
>
>> The following bug has been logged on the website:
>>
>> Bug reference: 18403
>> Logged by: Jiangshan Liu
>> Email address: jiangshan.liu@tju.edu.cn
>> PostgreSQL version: 15.2
>> Operating system: Ubuntu
>> Description:
>>
>> Hi, I think PL/pgSQL is reporting unexpected errors when dealing with
>> DECLARE blocks paired with <<label>>.
>> 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;
>> $$;
>
>
>
> The failure to report an error here seems contrary to the documentation.
> When the end of the DO text is reached and only a single begin/end pair is
> seen the parser is being loose in being OK that one of the declares was not
> associated with a full block.
>
One block can have more DECLAREs
I am not sure if the empty list for DECLARE should be valid, but plpgsql
parser allows it.
do $$
declare x int;
declare y int;
begin
x := 1; y := 1;
raise notice '% %', x,y;
end;
$$;
> David J.
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>>
@ 2024-03-20 21:02 Tom Lane <tgl@sss.pgh.pa.us>
parent: PG Bug reporting form <noreply@postgresql.org>
2 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2024-03-20 21:02 UTC (permalink / raw)
To: jiangshan.liu@tju.edu.cn; +Cc: pgsql-bugs@lists.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
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2024-03-20 21:02 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 19:35 BUG #18403: PL/pgSQL is reporting unexpected errors when processing DECLARE blocks with <<label>> PG Bug reporting form <noreply@postgresql.org>
2024-03-20 20:37 ` Pavel Stehule <pavel.stehule@gmail.com>
2024-03-20 20:47 ` David G. Johnston <david.g.johnston@gmail.com>
2024-03-20 20:57 ` Pavel Stehule <pavel.stehule@gmail.com>
2024-03-20 21:02 ` Tom Lane <tgl@sss.pgh.pa.us>
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