相信用惯了Oracle的同学刚迁到Greenplum平台后会特别不适应,因为Oracle中常用的rownum在PG系列中没有啊。但是大家别着急,我们可以通过开窗函数模拟类似rownum的列来使用。
SQL如下,ID列类似rownum:
postgres=# \a
Output format is aligned.
postgres=# select row_number() over() as id, t.* from pg_tables t;
-[ RECORD 1 ]------------------------------
id | 1
schemaname | gp_toolkit
tablename | __gp_localid
tableowner | hgimdb
tablespace |
hasindexes | f
hasrules | f
hastriggers | f
-[ RECORD 2 ]------------------------------
id | 2
schemaname | gp_toolkit
tablename | __gp_masterid
tableowner | hgimdb
tablespace |
hasindexes | f
hasrules | f
hastriggers | f
-[ RECORD 3 ]------------------------------
id | 3
schemaname | gp_toolkit
tablename | __gp_log_segment_ext
tableowner | hgimdb
tablespace |