Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cfUYk-0004GG-37 for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Feb 2017 16:42:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cfUYj-0004qh-Mb for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Feb 2017 16:42:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cfUY3-0003ML-KT for pgsql-bugs@postgresql.org; Sun, 19 Feb 2017 16:41:19 +0000 Received: from smtp-out.abv.bg ([194.153.145.99]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cfUXy-0003EE-Tj for pgsql-bugs@postgresql.org; Sun, 19 Feb 2017 16:41:18 +0000 Received: from nm33.abv.bg (nm33.ni.bg [192.168.151.4]) by smtp-out.abv.bg (Postfix) with ESMTP id 3B953D53; Sun, 19 Feb 2017 18:41:09 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=abv.bg; s=smtp-out; t=1487522469; bh=PKkUWsrzmbWx6MYt3mgQTrrTAAEsg0mRO7VU6D4sKxU=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=UECWH5tRCJbVP2ntdFSPKlgA2Qr1MaX3pc4j+sfoARn8hDGuAic9chzvi3RM6KNk4 u8ikYfd7JbRwvIZ4DR1RghYugMxhJEIDCQktly3LAFznQA89vwGxAaRaOQpC4Gps6o A4Sv3Eg3ZAmob2UqzSKwsfUj98fl1AWdsqnuCE9E= Received: from nm33.abv.bg (localhost [127.0.0.1]) by nm33.abv.bg (Postfix) with ESMTP id 24EEA12009E; Sun, 19 Feb 2017 18:41:09 +0200 (EET) Date: Sun, 19 Feb 2017 18:41:09 +0200 (EET) From: Stefan Stefanov To: Tom Lane Cc: Wei Congrui , Pavel Stehule , "\"\"\"\"\"\"\"\"\"\"\"\"\"\"pgsql-bugs@postgresql.org\"\"\"\"\"\"\"\"\"\"\"\"\"\"" Message-ID: <1908368489.826635.1487522469150.JavaMail.apache@nm33.abv.bg> In-Reply-To: <21576.1487350461@sss.pgh.pa.us> References: <20170217075821.6101.49074@wrigleys.postgresql.org> <21576.1487350461@sss.pgh.pa.us> Subject: Re: BUG #14549: pl/pgsql parser MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_826634_1556436347.1487522469131" X-Mailer: AbvMail 3.0 X-Originating-IP: 93.152.141.105 X-Pg-Spam-Score: -1.7 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------=_Part_826634_1556436347.1487522469131 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit The documentation keeps the door open. Two compatible suggestions: SET plpgsql_syntax TO strict; -- with loose as default The parser becomes strict about the placement of INTO (as the manual hints) and about the number and type of SELECT output columns matching the number of INTO target variables. A warning and a hint rather then an exception to keep backwards compatibility Sincerely, Stefan >-------- Оригинално писмо -------- >От: Tom Lane tgl@sss.pgh.pa.us >Относно: Re: [BUGS] BUG #14549: pl/pgsql parser >До: Wei Congrui >Изпратено на: 17.02.2017 18:54 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 ------=_Part_826634_1556436347.1487522469131 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable The documentation keeps the door open. Two compatible suggestions:
    <= li>SET plpgsql_syntax TO strict; -- with loose as default
The pars= er becomes strict about the placement of INTO (as the manual hints) and abo= ut the
number and type of SELECT output columns matching the number of INTO target= variables.
  • A warning and a hint rather then an exception to kee= p backwards compatibility

Sincerely,=20 Stefan



>-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=BD=D0=BE = =D0=BF=D0=B8=D1=81=D0=BC=D0=BE --------
>=D0=9E=D1=82: Tom Lane tgl@sss.pgh.pa.us
>=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: [BUGS] BUG #14549:= pl/pgsql parser
>=D0=94=D0=BE: Wei Congrui <crvv.mail@gmail.com>
>=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0=BD=D0= =B0: 17.02.2017 18:54

Wei Congrui <crvv.mail@gmail.com> writes:
> In the document,
> https://www.postgr= esql.org/docs/9.6/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONE= ROW
> "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

=09SELECT 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

=09SELECT 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.

=09=09=09regards, tom lane
------=_Part_826634_1556436347.1487522469131--