array_agg() is a database function to aggregate an attribute from different rows into a single array. It is a built-in function in PostgreSQL, HSQLDB and DB2.
The array_agg()
aggregate function is defined in the ANSI SQL:2008 specification. It aggregates an attribute from a set of source rows into a single array with a value for each of the attributes. The data type of the attribute is preserved in the array.
The array_agg()
function is supported by PostgreSQL (8.4 and later), HSQLDB and DB2 (at least since 9.5.0).
Other DBMSs use alternative functions such as listagg()
(Oracle) or group_concat()
(MySQL and SQLLite) but the resulting array contains string representations of the source row attributes.