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 T,NEXTVAL('ROWNUMSEQ') AS ROWNUM FROM TEST;
t | rownum
----+--------
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5
6 | 6
7 | 7
8 | 8
9 | 9
10 | 10
11 | 11
12 | 12
13 | 13
14 | 14
--Dinesh
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 T,NEXTVAL('ROWNUMSEQ') AS ROWNUM FROM TEST;
t | rownum
----+--------
1 | 1
2 | 2
3 | 3
4 | 4
5 | 5
6 | 6
7 | 7
8 | 8
9 | 9
10 | 10
11 | 11
12 | 12
13 | 13
14 | 14
--Dinesh
That is a goοԁ tір particulkarly
ReplyDeleteto those nеω to the blogosphere.
Short buut very acсuratе information… Thanks for ѕhаring thіѕ one.
A must read post!
Feel free to viѕit my blοg ::
tarot gratuit
This comment has been removed by a blog administrator.
ReplyDeleteThank You.
DeleteWould you be all for exchanging hyperlinks? online casinos for us players
ReplyDelete