Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Pavel Kulakov <paul(dot)kulakov(at)systematica(dot)ru>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement
Date: 2023-11-15 07:33:15
Message-ID: CAFj8pRD-AtjXTb3hxtrzOy6NK=SKWdQ0s03_3TTsch5uQv9+ew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi

st 15. 11. 2023 v 8:23 odesílatel Pavel Kulakov <paul(dot)kulakov(at)systematica(dot)ru>
napsal:

> Hi Tom,
>
> Thanks for your answer.
> I set plpgsql.extra_errors = 'strict_multi_assignment'
>
> Now, how to explain the following working?
>
> do $sql$
> declare
> _n int; _s text;
> begin
> select 1 into _n _s;
> raise notice '_n = %, _s = %', _n, _s;
> end;
> $sql$;
>

looks so parser is not sensitive to garbage after variable name

(2023-11-15 08:27:11) postgres=# do $sql$
declare
_n int; _s text;
begin
select 1 into _n somegarbage;
raise notice '_n = %, _s = %', _n, _s;
end;
$sql$;
NOTICE: _n = 1, _s = <NULL>
DO

>
> Regards,
> Pavel
>
> -----Original Message-----
> From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
> Sent: Tuesday, November 14, 2023 6:31 PM
> To: paul(dot)kulakov(at)systematica(dot)ru
> Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
> Subject: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO
> statement
>
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > 1. The following code is successfully executed although it has
> > incorrect
> > syntax: there must be comma (,) between _n and _s in 'into' section.
>
> > select 1, 'string1', 'string2'
> > into _n _s;
>
> I believe this is being read the same as
>
> select 1, 'string1', 'string2' _s into _n;
>
> That is, the lack of a comma causes the INTO sub-clause to end, and then _s
> is taken as an AS-less column label. As the manual explains, for
> backwards-compatibility reasons we allow INTO to be embedded anywhere in
> the
> command, even though that leads to surprising-looking cases like this one.
>
> As for the question of why you don't get an error for the wrong number of
> INTO targets, again that's backwards compatibility.
> There's a "strict_multi_assignment" check you can turn on to make it
> complain about that [1].
>
> regards, tom lane
>
> [1]
>
> https://www.postgresql.org/docs/current/plpgsql-development-tips.html#PLPGSQ
> L-EXTRA-CHECKS
> <https://www.postgresql.org/docs/current/plpgsql-development-tips.html#PLPGSQL-EXTRA-CHECKS>
>
>
>
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Kulakov 2023-11-15 07:38:42 RE: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement
Previous Message Pavel Kulakov 2023-11-15 07:22:53 RE: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement