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() 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
SELECT
    f1 := ZIP(ARRAY[100, 200, 300] AS id, ARRAY['a', 'b', 'c'] AS v).TRANSFORM(SELECT ROW_NUMBER() OVER (ORDER BY id ASC)).UNWRAP() -- 1-based position in ORDER BY order, not id (100, 200, 300) and not v
;
Result
f1 ARRAY
[1, 2, 3]

Last update at: 2026/05/26 17:22:09