select row_number() over (order by <field> nulls last) as rownum, *
from foo_tbl
order by <field>
Pokud není objednávka nutná, lze tuto odpověď také zjednodušit:
select row_number() over(), * -- notice: no fields are needed
from foo_tbl
SQL Fiddle Proof of Concept