location
sträng liknar en textmatris. Konvertera den till text[]
och unnest:
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)
Eller ännu enklare, casta strängen till jsonb
och använd 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