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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Date: 2022-09-19 17:05:16
Message-ID: 456815.1663607116@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bryn Llewellyn <bryn(at)yugabyte(dot)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

In response to

Browse pgsql-general by date

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