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 1r2vNi-001PBi-2u for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Nov 2023 15:31:14 +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 1r2vNe-008M80-UH for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Nov 2023 15:31:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2vNe-008M7s-LV for pgsql-bugs@lists.postgresql.org; Tue, 14 Nov 2023 15:31:10 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2vNX-005YMB-D6 for pgsql-bugs@lists.postgresql.org; Tue, 14 Nov 2023 15:31:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3AEFV1QR2486682; Tue, 14 Nov 2023 10:31:02 -0500 From: Tom Lane To: paul.kulakov@systematica.ru cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18195: PL/pgSQL: invalid syntax allowed in SELECT INTO statement In-reply-to: <18195-95ee8b48a9d7cd93@postgresql.org> References: <18195-95ee8b48a9d7cd93@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Tue, 14 Nov 2023 13:00:00 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2486680.1699975861.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 14 Nov 2023 10:31:01 -0500 Message-ID: <2486681.1699975861@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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#= PLPGSQL-EXTRA-CHECKS