aqh
aqh

Reputation: 15

How to Convert Oracle Sql to Postgresql

My SQL query has "connect by regexp_substr". How do I convert it to PostgreSQL 10 query ?

I have tried this in Ubuntu and toad...

  select regexp_substr('1,2,4','[^,]+', 1, level) from dual
    connect by regexp_substr('1,2,4', '[^,]+', 1, level) is not null;

How to do I get convert above query to PostgreSQL version 10?

Upvotes: 1

Views: 316

Answers (2)

user330315
user330315

Reputation:

string_to_array() is typically faster if no regular expression is needed.

select *
from unnest(string_to_array('1,2,4', ',')) as t(c);

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269603

If I understand correctly, you want to split a comma-delimited string into rows. For that, use regexp_split_to_table():

select regexp_split_to_table('1,2,4', ',')

In Postgres, it is possible that you would really phrase the overall query using arrays. If you have a question about a larger query, ask in a new question.

Upvotes: 1

Related Questions