Der location
string ähnelt einem Textarray. Wandeln Sie es in text[]
um und entschachteln:
with my_data(id, location) as (
values
(1, '["Humboldt, TN","Medina, TN","Milan, TN"]')
)
select id, unnest(format('{%s}', trim(location, '[]'))::text[]) as location
from my_data
id | location
----+--------------
1 | Humboldt, TN
1 | Medina, TN
1 | Milan, TN
(3 rows)
Oder noch einfacher, wandeln Sie den String in jsonb
um und verwenden Sie jsonb_array_elements_text()
:
with my_data(id, location) as (
values
(1, '["Humboldt, TN","Medina, TN","Milan, TN"]')
)
select id, jsonb_array_elements_text(location::jsonb) as location
from my_data