Aggregate values into an array/JSON-array, dispatched per-dialect.
PostgreSQL / CockroachDB: native ARRAY_AGG([DISTINCT] expr [ORDER BY col [ASC|DESC]]).
Snowflake: native ARRAY_AGG([DISTINCT] expr) [WITHIN GROUP (ORDER BY col [ASC|DESC])]
— Snowflake's ARRAY_AGG uses the same WITHIN GROUP placement as LISTAGG,
not Postgres's inline ORDER BY.
ClickHouse: native groupArray(expr) (distinct: groupUniqArray(expr));
returns ClickHouse's native Array(T) type. No inline ORDER BY support
(same limitation as stringAgg) — throws if orderBy is requested.
MySQL (5.7.22+) / MariaDB (10.5+): no ARRAY_AGG, but both support
the real JSON_ARRAYAGG(expr) function, used here as a JSON-array
fallback. Neither dialect's JSON_ARRAYAGG supports DISTINCT or
ORDER BY — both throw if requested.
Oracle (12.2+) / Db2 (11.5+): no ARRAY_AGG, but both support the
real SQL:2016 JSON_ARRAYAGG(expr) function, used as a JSON-array
fallback here too. DISTINCT/ORDER BY throw (not supported by either
engine's JSON_ARRAYAGG).
SQLite: no ARRAY_AGG, but has the real native json_group_array(expr)
aggregate, used as the fallback. DISTINCT/ORDER BY throw (not
supported by SQLite's json_group_array).
MSSQL / Redshift: no real array-aggregation concept and no reliable
scalar-aggregate JSON-array equivalent (MSSQL's JSON array construction
is via FOR JSON PATH on a full query shape, not an aggregate function
usable inline in a SELECT list; Redshift has no JSON_ARRAYAGG). Both
throw a clear "not supported" error rather than faking an unreliable
workaround.
Aggregate values into an array/JSON-array, dispatched per-dialect.
ARRAY_AGG([DISTINCT] expr [ORDER BY col [ASC|DESC]]).ARRAY_AGG([DISTINCT] expr) [WITHIN GROUP (ORDER BY col [ASC|DESC])]— Snowflake's ARRAY_AGG uses the same WITHIN GROUP placement as LISTAGG, not Postgres's inline ORDER BY.groupArray(expr)(distinct:groupUniqArray(expr)); returns ClickHouse's native Array(T) type. No inline ORDER BY support (same limitation asstringAgg) — throws iforderByis requested.ARRAY_AGG, but both support the realJSON_ARRAYAGG(expr)function, used here as a JSON-array fallback. Neither dialect'sJSON_ARRAYAGGsupportsDISTINCTorORDER BY— both throw if requested.ARRAY_AGG, but both support the real SQL:2016JSON_ARRAYAGG(expr)function, used as a JSON-array fallback here too.DISTINCT/ORDER BYthrow (not supported by either engine's JSON_ARRAYAGG).ARRAY_AGG, but has the real nativejson_group_array(expr)aggregate, used as the fallback.DISTINCT/ORDER BYthrow (not supported by SQLite's json_group_array).FOR JSON PATHon a full query shape, not an aggregate function usable inline in a SELECT list; Redshift has no JSON_ARRAYAGG). Both throw a clear "not supported" error rather than faking an unreliable workaround.