Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1celnp-0001uW-7K for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Feb 2017 16:54:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1celno-0000M8-Qi for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Feb 2017 16:54:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1celno-0000La-2o for pgsql-bugs@postgresql.org; Fri, 17 Feb 2017 16:54:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1celnk-0007zQ-Ui for pgsql-bugs@postgresql.org; Fri, 17 Feb 2017 16:54:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v1HGsL9E021577; Fri, 17 Feb 2017 11:54:21 -0500 From: Tom Lane To: Wei Congrui cc: Pavel Stehule , stefanov.sm@abv.bg, "pgsql-bugs@postgresql.org" Subject: Re: BUG #14549: pl/pgsql parser In-reply-to: References: <20170217075821.6101.49074@wrigleys.postgresql.org> Comments: In-reply-to Wei Congrui message dated "Fri, 17 Feb 2017 17:44:46 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21575.1487350461.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 17 Feb 2017 11:54:21 -0500 Message-ID: <21576.1487350461@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Wei Congrui writes: > In the document, > https://www.postgresql.org/docs/9.6/static/plpgsql-statements.html#PLPGSQ= L-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 --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs