Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3AEq-002RjL-LN for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Nov 2023 07:23:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r3AEp-00EQDI-23 for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Nov 2023 07:23:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3AEo-00EQD9-P2 for pgsql-bugs@lists.postgresql.org; Wed, 15 Nov 2023 07:23:02 +0000 Received: from h55.sserv.ru ([95.215.177.133]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r3AEh-006WbP-LD for pgsql-bugs@lists.postgresql.org; Wed, 15 Nov 2023 07:23:01 +0000 Received: from [194.190.106.52] (helo=kulakov) by h55.sserv.ru with esmtpa (Exim 4.92.3) (envelope-from ) id 1r3AEf-0005mB-Dt; Wed, 15 Nov 2023 10:22:53 +0300 From: "Pavel Kulakov" To: "'Tom Lane'" Cc: References: <18195-95ee8b48a9d7cd93@postgresql.org> <2486681.1699975861@sss.pgh.pa.us> In-Reply-To: <2486681.1699975861@sss.pgh.pa.us> Subject: RE: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement Date: Wed, 15 Nov 2023 10:22:53 +0300 Message-ID: <001501da1794$8c3baa10$a4b2fe30$@systematica.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Content-Language: ru Thread-Index: AQHU2ZXcvcQNKHg1XihmYBUfGbDXmQI/xV33sHN1/MA= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Tom, Thanks for your answer. I set plpgsql.extra_errors = 'strict_multi_assignment' Now, how to explain the following working? do $sql$ declare _n int; _s text; begin select 1 into _n _s; raise notice '_n = %, _s = %', _n, _s; end; $sql$; Regards, Pavel -----Original Message----- From: Tom Lane Sent: Tuesday, November 14, 2023 6:31 PM To: paul.kulakov@systematica.ru Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement PG Bug reporting form 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#PLPGSQ L-EXTRA-CHECKS