Reputation: 408
I have a query like this:
select value from some_table_name where key='some_key'
The result is 1 row only. It is a text with commas
apple,banana,orange
How can I use that result in this below query?
SELECT unnest(
string_to_array('use above text from query in here', ',')
) AS parts;
Upvotes: 0
Views: 25
Reputation:
You can use the unnest directly in the FROM clause:
select u.*
from some_table_name t
cross join unnest(string_to_array(t.value, ',')) as u(val)
where t.key='some_key';
Or with a current version of Postgres:
select u.*
from some_table_name t
cross join string_to_table(t.value, ',') as u(val)
where t.key='some_key'
Upvotes: 1