Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaKCy-0002iW-3O for pgsql-general@arkaria.postgresql.org; Mon, 19 Sep 2022 17:05:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oaKCx-0006zK-22 for pgsql-general@arkaria.postgresql.org; Mon, 19 Sep 2022 17:05:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaKCw-0006zB-Nu for pgsql-general@lists.postgresql.org; Mon, 19 Sep 2022 17:05:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oaKCu-0007Vi-1u for pgsql-general@lists.postgresql.org; Mon, 19 Sep 2022 17:05:22 +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 28JH5GFT456816; Mon, 19 Sep 2022 13:05:16 -0400 From: Tom Lane To: Bryn Llewellyn cc: Adrian Klaver , pgsql-general list Subject: Re: =?utf-8?B?UmU6IFdoZXJlJ3MgdGhlIGRvYyBmb3IgImFycmF5KCkiIOKAlCBh?= =?utf-8?B?cyBpbiAic2VsZWN0IGFycmF5KHZhbHVlcyAoMTcpLCAoNDIpKSI=?= In-reply-to: References: <257592.1663561881@sss.pgh.pa.us> Comments: In-reply-to Bryn Llewellyn message dated "Mon, 19 Sep 2022 09:43:54 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <456814.1663607116.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 19 Sep 2022 13:05:16 -0400 Message-ID: <456815.1663607116@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bryn Llewellyn writes: > This works fine: > select length( (select 'dog') ) > But without the doubled parentheses, it causes a syntax error. The parens are required for it to be a valid scalar subquery, as per https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-SC= ALAR-SUBQUERIES The reason ARRAY() is different is exactly that its argument is directly a subquery, not an expression that chances to be a scalar subquery. > On the other hand, an extra pair of surrounding parentheses here > select array( (values (17), (42)) ) > while not necessary, *is* tolerated. You can pretty much always add *extra* parens in any expression context. regards, tom lane