postgresqlHow do I use the PostgreSQL array_agg function?
The PostgreSQL array_agg
function is used to aggregate values from a group of rows into a single array. It takes an expression as an argument and returns an array containing all the values from the group.
Example
SELECT array_agg(name)
FROM users
Output example
{'John', 'Mary', 'James'}
This example returns an array containing the name
values from the users
table.
Code explanation
SELECT
- specifies the columns to be selectedarray_agg
- the PostgreSQL array_agg functionname
- the expression to be aggregated into an arrayFROM users
- specifies the table from which to select the values
Helpful links
More of Postgresql
- How can I use PostgreSQL XML functions to manipulate XML data?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How do I use PostgreSQL with Qt?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL's "zero if null" feature?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL with YAML?
See more codes...