I'm trying to get some result like this:
rownumber | value
1 | a
2 | b
3 | c
Without any tables I'm doing something like this:
WITH RECURSIVE t(rownumber, value) AS (
select 1, regexp_split_to_table('a, b, c', ',')
UNION ALL
SELECT rownumber+1, regexp_split_to_table('a, b, c',',') FROM t
)
SELECT * FROM t limit (select count(*) from regexp_split_to_table('a, b, c', ','));
But the results are not as expected.
The reason I'm doing this is because the value 'a, b, c' should be some variable.
In Oracle the SQL looks like this:
SELECT value FROM (
SELECT ROWNUM AS rownumber, trim(REGEXP_SUBSTR('a, b, c','[^,]+', 1, LEVEL)) AS value
FROM DUAL CONNECT BY trim(REGEXP_SUBSTR('a, b, c', '[^,]+', 1, LEVEL)) IS NOT NULL
)
and It works.
What am I doing wrong in Postgresql?