New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Old versions: 3.7 | 3.6

ARRAY_AGG

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The ARRAY_AGG aggregate function aggregates grouped values into an array. It supports being used with an ORDER BY clause.

SELECT
  array_agg(ID)
  array_agg(ID ORDER BY ID DESC)
FROM BOOK
create.select(
         arrayAgg(BOOK.ID),
         arrayAgg(BOOK.ID).orderBy(BOOK.ID.desc()))
      .from(BOOK)

Producing:

+--------------+--------------+
| array_agg    | array_agg    |
+--------------+--------------+
| [1, 3, 4, 2] | [4, 3, 2, 1] |
+--------------+--------------+

Dialect support

This example using jOOQ:

arrayAgg(BOOK.ID)

Translates to the following dialect specific expressions:

-- AURORA_POSTGRES, COCKROACHDB, HSQLDB, POSTGRES
array_agg(BOOK.ID)

-- ACCESS, ASE, AURORA_MYSQL, DB2, DERBY, FIREBIRD, H2, HANA, INFORMIX, INGRES, MARIADB, MEMSQL, MYSQL, ORACLE, REDSHIFT, 
-- SQLDATAWAREHOUSE, SQLITE, SQLSERVER, SYBASE, TERADATA, VERTICA
/* UNSUPPORTED */

(These are currently generated with jOOQ 3.15, see #10141)

The jOOQ Logo