SEQUENCE()
All functions > ARRAY > SEQUENCE()
Generates an inclusive array from start to stop. Accepts integers with an optional step (default 1), dates with an optional INTERVAL step (default one day), or timestamps with a required INTERVAL step.
Signatures
Integer sequence
Returns: Array of integers in the sequence
SEQUENCE(start: BIGINT, stop: BIGINT, [step: BIGINT]) → ARRAY<BIGINT> sql
| Parameter | Type | Required | Description |
|---|---|---|---|
start | BIGINT | Yes | Starting value (inclusive) |
stop | BIGINT | Yes | Ending value (inclusive) |
step | BIGINT | No | Step between elements (default: 1) |
Signature notes:
- Step defaults to 1; use a negative step for descending sequences
- Both start and stop are included in the result
Date sequence
Returns: Array of dates or timestamps in the sequence
SEQUENCE(start: DATE | TIMESTAMP, stop: DATE | TIMESTAMP, step: INTERVAL) → ARRAY<DATE> | ARRAY<TIMESTAMP> sql
| Parameter | Type | Required | Description |
|---|---|---|---|
start | `DATE | TIMESTAMP` | Yes |
stop | `DATE | TIMESTAMP` | Yes |
step | INTERVAL | Yes | Interval between elements (default for dates: one day; required for timestamps) |
Signature notes:
- The INTERVAL step defaults to one day for dates; it is required for timestamps
- Month-based intervals respect calendar month boundaries
- Both start and stop are included when reachable by the given step
Notes
- Generates sequence from start to stop inclusive
- For integers: step defaults to 1; use a negative step for descending sequences
- For dates the INTERVAL step defaults to one day; for timestamps it is required
- Month-based intervals (e.g.
1 month) respect calendar month boundaries - If start equals stop the result contains exactly one element
- Bind a date SEQUENCE in FOR CROSS against a fact INPUT to reconstruct a value on every calendar day; see help('date_spine')
Aliases
RANGEGENERATE_SERIES
See also
Examples
Integer sequences
FeatureQL
RETURN
-- Default step 1
f1 := SEQUENCE(1, 5),
-- Descending with negative step
f2 := SEQUENCE(5, 1, -1),
-- Single-point range
f3 := SEQUENCE(3, 3)
;Result
| f1 ARRAY | f2 ARRAY | f3 ARRAY |
|---|---|---|
| [1, 2, 3, 4, 5] | [5, 4, 3, 2, 1] | [3] |
Date sequences
FeatureQL
RETURN
-- Day-by-day sequence
f1 := SEQUENCE(
DATE '2024-01-01',
DATE '2024-01-05',
INTERVAL_PARSE('1 day')
)
;Result
| f1 ARRAY |
|---|
| [2024-01-01, 2024-01-02, 2024-01-03, 2024-01-04, 2024-01-05] |
Timestamp sequences
FeatureQL
RETURN
-- Monthly steps respect calendar boundaries (leap year Feb)
f1 := SEQUENCE(
DATE '2024-01-31',
DATE '2024-04-30',
INTERVAL_PARSE('1 month')
)
;Result
| f1 ARRAY |
|---|
| [2024-01-31, 2024-02-29, 2024-03-29, 2024-04-29] |