STRING_AGG() OVER ...
All functions > WINDOW FUNCTION > STRING_AGG() OVER ...
Concatenates string values in the window frame in order up to the current row, separated by the delimiter.
Syntax
STRING_AGG(expr, delimiter) [FILTER (WHERE condition) | WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- SQL translation is implemented only when the current SQL backend is DuckDB
- Requires a well-defined window (ORDER BY, and optionally PARTITION BY and frame)
- NULL values are ignored where the underlying window aggregate skips NULLs
See also
Examples
FeatureQL
SELECT
-- Running string concatenation with a delimiter that avoids commas inside elements
f1 := ZIP(
ARRAY(1, 2, 3, 4) AS id,
ARRAY(30, 10, 20, 5) AS v,
ARRAY('a', 'b', 'c', 'd') AS s
).TRANSFORM(SELECT STRING_AGG(s, '|') OVER (ORDER BY id ASC)).UNWRAP(),
-- Running concatenation counting only rows where v > 15 (10 and 5 excluded from the frame)
f2 := ZIP(
ARRAY(1, 2, 3, 4) AS id,
ARRAY(30, 10, 20, 5) AS v,
ARRAY('a', 'b', 'c', 'd') AS s
).TRANSFORM(
SELECT STRING_AGG(s, '|') FILTER (WHERE v > 15) OVER (ORDER BY id ASC)
).UNWRAP()
;Result
| f1 ARRAY | f2 ARRAY |
|---|---|
| [a, a|b, a|b|c, a|b|c|d] | [a, a, a|c, a|c] |