pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Wei Congrui <crvv.mail@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: stefanov.sm@abv.bg, "pgsql-bugs@postgresql.org" <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14549: pl/pgsql parser
Date: Fri, 17 Feb 2017 11:54:21 -0500
Message-ID: <21576.1487350461@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPxZtjFV-srjvzLgL+sYtBmqsLpH_M1WLy1m55Ek-9RUtRhaFA@mail.gmail.com>
References: <20170217075821.6101.49074@wrigleys.postgresql.org>
	<CAFj8pRCU+QFD5J1VPdN568T4MUZ0ao5Yauxvh11+1NOL4nO+hQ@mail.gmail.com>
	<CAPxZtjFV-srjvzLgL+sYtBmqsLpH_M1WLy1m55Ek-9RUtRhaFA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Wei Congrui <crvv.mail@gmail.com> writes:
> In the document,
> https://www.postgresql.org/docs/9.6/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW
> "If a row or a variable list is used as target, the query's result
> columns must exactly match the structure of the target as to
> number and data types, or else a run-time error occurs. When
> a record variable is the target, it automatically configures itself
> to the row type of the query result columns."

> I think this is a bug according to the document.

I don't think that's the relevant point.  What is relevant is the
next paragraph:

  "The INTO clause can appear almost anywhere in the SQL
  command. Customarily it is written either just before or just after the
  list of select_expressions in a SELECT command, or at the end of the
  command for other command types. It is recommended that you follow this
  convention in case the PL/pgSQL parser becomes stricter in future
  versions."

What's happening in Stefan's example

	SELECT 1, 2, 3 INTO vara, varb AS varc;

is that "INTO vara, varb" is pulled out as being the INTO clause, and
what's left is

	SELECT 1, 2, 3 AS varc;

which is a perfectly legal SQL statement so no error is reported.

To make this throw an error, we'd need to become stricter about the
placement of INTO (as the manual hints), or become stricter about the
number of SELECT output columns matching the number of INTO target
variables, or possibly both.  Any such change would doubtless draw
complaints from people whose code worked fine before.  It might be
a good idea anyway, but selling backwards-compatibility breakage
to the Postgres community is usually a hard sell.

			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



view thread (10+ messages)  latest in thread

Message-ID: <21576.1487350461@sss.pgh.pa.us>
Permalink:  ../21576.1487350461@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21576.1487350461@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 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, crvv.mail@gmail.com, pavel.stehule@gmail.com
  Subject: Re: BUG #14549: pl/pgsql parser
  In-Reply-To: <21576.1487350461@sss.pgh.pa.us>
  References: <20170217075821.6101.49074@wrigleys.postgresql.org> <CAFj8pRCU+QFD5J1VPdN568T4MUZ0ao5Yauxvh11+1NOL4nO+hQ@mail.gmail.com> <CAPxZtjFV-srjvzLgL+sYtBmqsLpH_M1WLy1m55Ek-9RUtRhaFA@mail.gmail.com> <21576.1487350461@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