RECURSE(...)
All functions > ARRAY OF ROWS > RECURSE(...)
Produces an array of rows by iterating a seed ROW, optionally traversing entity relationships
Syntax
ROW(...).RECURSE( [ WITH local_binding := expr, ... ] SELECT field_definitions [ WHILE condition ] [ VIA field BIND TO feature FOLLOW feature ] MAX_LEVEL n )
Availability
Available on DuckDB. Not available on Trino, Serving.
Related Functions
Examples
Count until n reaches 5
FeatureQL
DEFINE
seed_n := INPUT(BIGINT)
RETURN
seed_n,
result := ROW(seed_n AS n).RECURSE(
RETURN n := prev[n] + 1
WHILE n < 5
MAX_LEVEL 10
)
FOR
seed_n := BIND_VALUES(ARRAY(1, 10))
;Result
| SEED_N BIGINT | RESULT ARRAY<ROW<level BIGINT, is_cycle BOOLEAN, is_max_level BOOLEAN, n BIGINT>> |
|---|---|
| 1 | [{level: 0, is_cycle: false, is_max_level: false, n: 1}, {level: 1, is_cycle: false, is_max_level: false, n: 2}, {level: 2, is_cycle: false, is_max_level: false, n: 3}, {level: 3, is_cycle: false, is_max_level: false, n: 4}] |
| 10 | [{level: 0, is_cycle: false, is_max_level: false, n: 10}] |