pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: paul.kulakov@systematica.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement
Date: Tue, 14 Nov 2023 10:31:01 -0500
Message-ID: <2486681.1699975861@sss.pgh.pa.us> (raw)
In-Reply-To: <18195-95ee8b48a9d7cd93@postgresql.org>
References: <18195-95ee8b48a9d7cd93@postgresql.org>

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





view thread (8+ messages)  latest in thread

Message-ID: <2486681.1699975861@sss.pgh.pa.us>
Permalink:  ../2486681.1699975861@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2486681.1699975861@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, paul.kulakov@systematica.ru, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement
  In-Reply-To: <2486681.1699975861@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