Re: Re: Where's the doc for "array()" — as in "select array(values (17), (42))" - Mailing list pgsql-general

From Tom Lane
Subject Re: Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Date
Msg-id 456815.1663607116@sss.pgh.pa.us
Whole thread Raw
In response to Re: Where's the doc for "array()" — as in "select array(values (17), (42))"  (Bryn Llewellyn <bryn@yugabyte.com>)
List pgsql-general
Bryn Llewellyn <bryn@yugabyte.com> 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-SCALAR-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



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Next
From: Bryn Llewellyn
Date:
Subject: I slipped up so that no existing role allows connection. Is rescue possible?