Rownum in postgresql

johnlemon picture johnlemon · Oct 18, 2010 · Viewed 163.9k times · Source

Is there any way to simulate rownum in postgresql ?

Answer

baklarz2048 picture baklarz2048 · Oct 18, 2010

Postgresql > 8.4

SELECT 
    row_number() OVER (ORDER BY col1) AS i, 
    e.col1, 
    e.col2, 
    ... 
FROM ...