Reputation: 15
I Need inputs on Migration of CONNECT BY LEVEL from Oracle to Postgres.
Source Code from Oracle:
SELECT LEVEL,AST_TXRBATCHID_SEQ.NEXTVAL AS BATCH
from DUAL
CONNECT BY LEVEL <= '2';
Upvotes: 0
Views: 542
Reputation: 247270
A simple solution would be:
SELECT 1 AS level, nextval('ast_txrbatchid_seq') AS batch
UNION
SELECT 2, nextval('ast_txrbatchid_seq');
Upvotes: 0
Reputation: 31676
Use generate_series
and NEXTVAL()
function.
PostgreSQL 9.6 Schema Setup:
create sequence AST_TXRBATCHID_SEQ start with 1 increment by 1;
Query 1:
SELECT id,NEXTVAL('AST_TXRBATCHID_SEQ') AS BATCH
from generate_series(1,2) as id
| id | batch |
|----|-------|
| 1 | 2 |
| 2 | 3 |
Upvotes: 1