Skip to main content

Posts

Showing posts with the label rownum postgres

:: Rownum in postgresql ::

Hi All, As we know,we can generate rownum with window fuctions also(Rank).In oracle we have "rownum" pseduo column,but we don't in postgresql. Here is the one of the solution for generating rownum in postgresql. In Oracle ----------- SQL> CREATE SEQUENCE ROWNUMSEQ; Sequence created. SQL> SELECT EMPNO,ROWNUMSEQ.NEXTVAL AS "ROWNUM" FROM EMP; EMPNO ROWNUM ---------- ---------- 7369 1 7499 2 7521 3 7566 4 7654 5 7698 6 7782 7 7788 8 7839 9 7844 10 7876 11 7900 12 7902 13 7934 14 In PostgreSQL ---------------- postgres=# CREATE SEQUENCE ROWNUMSEQ; CREATE SEQUENCE postgres=# CREATE TABLE TEST(T INT); CREATE TABLE postgres=# INSERT INTO TEST VALUES(GENERATE_SERIES(1,14)); INSERT 0 14 postgres=# SELECT ...