From: Tom Lane <tgl@sss.pgh.pa.us>
To: Artiom Makarov <artiom.makarov@gmail.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: pl/pgsql incorrect syntax checking on select .... into ... ?
Date: Wed, 28 May 2014 15:01:32 -0400
Message-ID: <9369.1401303692@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPDRmz_2y5u2qNzrxJiD2=StopBhynGiZ381c6CM11oL0GTngQ@mail.gmail.com>
References: <CAPDRmz_2y5u2qNzrxJiD2=StopBhynGiZ381c6CM11oL0GTngQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Artiom Makarov <artiom.makarov@gmail.com> writes:
> Missed comma in select ... into construction don't raise ERROR both on
> compiling and run time.
Unfortunately, that's perfectly legal syntax :-(.
The first problem is that long ago, somebody failed to make up their mind
about where the INTO clause could go in a plpgsql SELECT INTO, and
thought it would be cute to allow it anywhere. What this means is
that the plpgsql parser gobbles as much as looks like a syntactically valid
variable list after INTO, and removes that from the statement, and then
sees if the main SQL parser likes what's left. So starting with
> -- ---- missed comma \/ ----
> select i1,i2, i3, i4 into var_i1,var_i2 var_i3, var_i4 from temp_table;
we remove "into var_i1,var_i2":
select i1,i2, i3, i4 var_i3, var_i4 from temp_table;
The second problem is that that's valid SQL syntax, because even longer
ago, somebody thought it'd be a good idea to allow AS to be omitted before
SELECT output aliases. So "var_i3" is a column alias to be applied to i4,
and then var_i4 is just a constant reference so far as this SELECT is
concerned.
The third problem is that SELECT INTO doesn't complain about extra output
columns; otherwise we might hope to at least get a complaint about that.
According to the comments in the source, this is necessary because
exec_move_row is sometimes applied to tuples from inheritance child tables
that might have extra physical columns. I'm not really sure that's still
true, but even if it's not, people might not appreciate it if we started
throwing an error for code that used to be accepted.
In short: we could only make this throw an error if we were willing to
break some subset of existing valid (more or less) queries.
Personally I've always thought that "INTO anywhere" was a pretty darn bad
idea, but it's probably much too late to change that.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, artiom.makarov@gmail.com
Subject: Re: pl/pgsql incorrect syntax checking on select .... into ... ?
In-Reply-To: <9369.1401303692@sss.pgh.pa.us>
References: <CAPDRmz_2y5u2qNzrxJiD2=StopBhynGiZ381c6CM11oL0GTngQ@mail.gmail.com> <9369.1401303692@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