Split a comma-separated record into its own rows
7
votes
1
answer
19326
views
I have the following table, named stores:
store_id INT
emails VARCHAR
That contains values:
store_id | emails
--- | ---
1 | user_1@example.com,user2@example.com
2 | uswe3@example.com,user4@example.com
4 | admin@example.com
And I want to generate the following set:
store_id | emails
--- | ---
1 | user_1@example.com
1 | user2@example.com
2 | uswe3@example.com
2 | user4@example.com
4 | admin@example.com
As you can see I want to split the emails field into a separate record containing only one email address.
Do you have any idea how I can do that?
So far I managed to create the following query:
select store_id,string_to_array(emails,',') from stores
But I don't know how I can split the string_to_array
to its own row.
Asked by Dimitrios Desyllas
(873 rep)
Jun 3, 2021, 11:11 AM
Last activity: Jun 4, 2021, 12:28 AM
Last activity: Jun 4, 2021, 12:28 AM