sql >> Base de Datos >  >> RDS >> PostgreSQL

¿Postgres divide la cadena con comillas dobles en varias filas?

La location string es similar a una matriz de texto. Conviértalo a text[] y anular:

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)

O incluso más simple, envíe la cadena a jsonb y usa 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

Db<>fiddle.