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

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Bryn Llewellyn <bryn(at)yugabyte(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-18 21:29:30
Message-ID: 45f7be19-f07d-2b34-f851-1b90c9b80ed6@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/18/22 13:25, Bryn Llewellyn wrote:
> I noticed that "array()" is used in the query that implements the "\du"
> psql meta-command. It has some similarity with "array_agg()" thus:
>
> create temporary view x(v) as (values (17), (42));
> select array_agg(v) from x;
> select array(select v from x);
>
> But there are differences. The "array()" function requires that its
> argument is a subquery that returns a single column. (Its data type can
> be composite.) But the "array_agg()" function's argument must be the
> select list in the larger context of a select statement—and in general
> together with "group by".
>

Lack of an explicit GROUP BY falls through to an implied one:

https://www.postgresql.org/docs/current/sql-select.html#SQL-GROUPBY

"If there are aggregate functions but no GROUP BY clause, the query is
treated as having a single group comprising all the selected rows."

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-09-19 00:00:07 Re: Where's the doc for "array()" — as in "select array(values (17), (42))"
Previous Message Adrian Klaver 2022-09-18 20:29:31 Re: Where's the doc for "array()" — as in "select array(values (17), (42))"