ROW_NUMBER() OVER ...
All functions > WINDOW FUNCTION > ROW_NUMBER() OVER ...
Returns a unique sequential number for each row within its partition, starting at 1.
Syntax
ROW_NUMBER() [WITHIN (WHERE condition)] OVER ([PARTITION BY expr [, ...]] [ORDER BY sort_item [, ...]] [ROWS|RANGE|GROUPS frame])
Notes
- Assigns a unique sequential number to each row within a partition
- Numbers start at 1 for the first row in each partition
- Unlike RANK, ROW_NUMBER always assigns unique numbers (no ties)
- ORDER BY determines the sequence of row numbers
- PARTITION BY creates independent numbering groups
- Useful for pagination, deduplication, and selecting top N rows per group
- Always returns consecutive numbers without gaps
See also
Examples
FeatureQL
-- 1-based position in ORDER BY order, not id (100, 200, 300) and not v
RETURN
f1 := ZIP(ARRAY(100, 200, 300) AS id, ARRAY('a', 'b', 'c') AS v).TRANSFORM(
RETURN ROW_NUMBER() OVER (ORDER BY id ASC)
).UNWRAP()
;Result
| f1 ARRAY<BIGINT> |
|---|
| [1, 2, 3] |