| From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
|---|---|
| To: | Bryn Llewellyn <bryn(at)yugabyte(dot)com> |
| Cc: | Tom Lane PostgreSQL <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Where's the doc for "array()" — as in "select array(values (17), (42))" |
| Date: | 2022-09-19 17:04:35 |
| Message-ID: | CAKFQuwZPAfoT6+ksGtTD2q6EBFrqUHJOG+2yM8xUJGi62NUYeQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Mon, Sep 19, 2022 at 9:44 AM Bryn Llewellyn <bryn(at)yugabyte(dot)com> wrote:
>
> There must be a significant difference between this:
>
> select 'dog'
>
That isn't anything in particular (it is a command by itself, it can be a
subquery in a FROM clause or the ARRAY() expression.
>
> and this:
>
> (select 'dog')
>
That is a scalar subquery the produces exactly one row and one column that
can be substituted in anyplace a single value is required.
> This works fine:
>
> select length( (select 'dog') )
>
> But without the doubled parentheses, it causes a syntax error.
>
Scalar subqueries are required to have surrounding parentheses.
https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-SCALAR-SUBQUERIES
"A scalar subquery is an ordinary SELECT query in parentheses that returns
exactly one row with one column."
> On the other hand, an extra pair of surrounding parentheses here
>
> select array( (values (17), (42)) )
>
> while not necessary, *is* tolerated.
>
An actual subquery works here so the parentheses are grouping in nature and
not an inherent part of the syntax.
David J.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2022-09-19 17:05:16 | Re: Re: Where's the doc for "array()" — as in "select array(values (17), (42))" |
| Previous Message | Bryn Llewellyn | 2022-09-19 16:43:54 | Re: Where's the doc for "array()" — as in "select array(values (17), (42))" |