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

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement
Дата
Msg-id CAFj8pRD3k_vFi9kGrA_SJc4bxLxT6k0=zu1tsg2BBrpHZ5SNJQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
Hi

út 14. 11. 2023 v 16:31 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:
PG Bug reporting form <noreply@postgresql.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#PLPGSQL-EXTRA-CHECKS

The extension plpgsql_check https://github.com/okbob/plpgsql_check can raise warnings for these cases too

Regards

Pavel
 

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement
Следующее
От: "Hayato Kuroda (Fujitsu)"
Дата:
Сообщение: RE: Logical replication is missing block of rows when sending initial sync?