Необходимо пронумеровать строки результата запроса:
# SELECT * FROM customers limit 10;
id | first_name | last_name
------+------------+-----------
8493 | Christy | Carney
8152 | Emilia | Melendez
4644 | Sydney | Calderon
7483 | Caroline | Daniel
8115 | Conor | Vang
9051 | Andrea | Melton
3778 | Howard | Wise
2756 | Albert | Galvan
1041 | Chelsey | Hampton
7639 | Bret | Mata
(10 rows)
Необходимо использовать window-функцию row_number():
# SELECT row_number() OVER(), * FROM customers limit 10;
row_number | id | first_name | last_name
------------+------+------------+-----------
1 | 8493 | Christy | Carney
2 | 8152 | Emilia | Melendez
3 | 4644 | Sydney | Calderon
4 | 7483 | Caroline | Daniel
5 | 8115 | Conor | Vang
6 | 9051 | Andrea | Melton
7 | 3778 | Howard | Wise
8 | 2756 | Albert | Galvan
9 | 1041 | Chelsey | Hampton
10 | 7639 | Bret | Mata
(10 rows)