pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Date: Mon, 19 Sep 2022 13:05:16 -0400
Message-ID: <456815.1663607116@sss.pgh.pa.us> (raw)
In-Reply-To: <FD968796-42C5-4FA1-AB61-66DD34049F79@yugabyte.com>
References: <F2DA0774-0B4D-4E72-8944-116154A57D98@yugabyte.com>
	<e6ac86e5-39f4-9704-7260-3f6c40c63b2d@aklaver.com>
	<C167E3BD-B650-4A8E-80A3-3307E70883C0@yugabyte.com>
	<257592.1663561881@sss.pgh.pa.us>
	<FD968796-42C5-4FA1-AB61-66DD34049F79@yugabyte.com>

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





view thread (12+ messages)

Message-ID: <456815.1663607116@sss.pgh.pa.us>
Permalink:  ../456815.1663607116@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/456815.1663607116@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bryn@yugabyte.com, adrian.klaver@aklaver.com
  Subject: Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
  In-Reply-To: <456815.1663607116@sss.pgh.pa.us>
  References: <F2DA0774-0B4D-4E72-8944-116154A57D98@yugabyte.com> <e6ac86e5-39f4-9704-7260-3f6c40c63b2d@aklaver.com> <C167E3BD-B650-4A8E-80A3-3307E70883C0@yugabyte.com> <257592.1663561881@sss.pgh.pa.us> <FD968796-42C5-4FA1-AB61-66DD34049F79@yugabyte.com> <456815.1663607116@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox