Skip to content
masterclass Buddy

PostgreSQL · Function

row_number

row_number gives each row a sequential number within its window partition, starting at 1. Use OVER with ORDER BY to define the numbering order.

Last updated

Syntax

row_number() OVER ( [ PARTITION BY partition_expression ] [ ORDER BY sort_expression [ ASC | DESC ] ] )

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • rank
  • dense_rank
  • lag
  • lead
  • OVER clause
  • PARTITION BY
  • WINDOW clause

Source: PostgreSQL: Documentation: 18: 9.22. Window Functions. Checked 2026-11-03.