我需要将从CONNECT BY LEVEL从Oracle迁移到Postgres的输入。
Oracle的源代码:
SELECT LEVEL,AST_TXRBATCHID_SEQ.NEXTVAL AS BATCH
from DUAL
CONNECT BY LEVEL <= '2';
答案 0 :(得分:1)
使用generate_series
和NEXTVAL()
功能。
PostgreSQL 9.6架构设置:
create sequence AST_TXRBATCHID_SEQ start with 1 increment by 1;
查询1 :
SELECT id,NEXTVAL('AST_TXRBATCHID_SEQ') AS BATCH
from generate_series(1,2) as id
<强> Results 强>:
| id | batch |
|----|-------|
| 1 | 2 |
| 2 | 3 |
答案 1 :(得分:0)
一个简单的解决方案是:
SELECT 1 AS level, nextval('ast_txrbatchid_seq') AS batch
UNION
SELECT 2, nextval('ast_txrbatchid_seq');