0

I try to translate the following oracle sql, which inserts 1000 rows with incremental values into a table:

insert into tableName (col1, col2, col3)
    select 'AN' || (1000000 + ROWNUM), 'EXT' || (9000000 + ROWNUM), ROWNUM
    from dual
    Connect By  ROWNUM <= 1000 ;

For Postgres support, i know i can substitute ROWNUM with ROW_NUMBER() OVER (), but i'm really getting a headache about translating the connect by statement. I have read about CTEs but i don't get how i can use this with an insert statement.

Does anyone know how to write this statement for postgresql? Thanks.

2 Answers 2

2

You can generate a series and just use that:

insert into tableName (col1, col2, col3)
    select 'AN' || (1000000 + g.n), 'EXT' || (9000000 + g.n), g.n
    from generate_series(1, 1000) g(n);
Sign up to request clarification or add additional context in comments.

Comments

1

Try generate_series.

 select 'AN' || (1000000 + ROWNUM), 'EXT' || (9000000 + ROWNUM),
 ROWNUM from generate_series(1,10000) as rownum ;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.