ARRAY_AGG() GROUP BY ...
All functions > GROUP BY > ARRAY_AGG() GROUP BY ...
Returns an array of the values in the group.
Syntax
Diagram(
Sequence(
Terminal("ARRAY_AGG"),
Terminal("("),
NonTerminal("expr"),
Terminal(")"),
Choice(0, Skip(),
Sequence(
Terminal("FILTER"),
Terminal("("),
Terminal("WHERE"),
NonTerminal("condition"),
Terminal(")")
)
),
Choice(0, Skip(),
Sequence(
Terminal("GROUP BY"),
OneOrMore(NonTerminal("feature"), Terminal(","))
)
)
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
expr | T | Yes | The expression to aggregate into an array |
condition | BOOLEAN | No | The condition to filter the values before aggregation |
feature | FEATURE | No | The features to group by (many features are supported) |
Notes
- Collects all values in a group into a single array
- Supports ORDER BY to control the order of elements in the result array
- Supports LIMIT to restrict the number of elements
- Can be combined with WHERE clause to filter values before aggregation
- NULL values are included in the result array
- Returns empty array if group has no values
- Use with GROUP BY to create arrays per group
Examples
FeatureQL
SELECT
f1 := ZIP(ARRAY[1, 2, 3, 4, 5] AS value).TRANSFORM(SELECT ARRAY_AGG(value)).UNWRAP_ONE() -- Array of values
;Result
| f1 ARRAY |
|---|
| [1, 2, 3, 4, 5] |