Description
Aggregates (collects) values from a group and returns a single array
Syntax
ARRAY_AGG(expression [ORDER BY sort_expression] [LIMIT count])
Parameters
| Parameter | Description | Data Type | Required |
|---|---|---|---|
| expression | Column or expression to evaluate | Any | Yes |
Notes
- Returns an empty array if the input is empty
- Returns only non-null values
- The array type depends on the input type (
Integer[],Text[], etc.) - Use
WITHIN GROUP (ORDER BY ...)to control the order of values in the resulting array. - When used as a window function, include an
OVER (...)clause. - To filter rows based on a window calculation, use
QUALIFYinstead ofWHERE.
Example
SELECT
ARRAY_AGG(full_name) WITHIN GROUP (ORDER BY full_name)
FROM
rippling.employee.Employee
GROUP BY
department;