'Postgres: Convert `character varying[]` to string
After loading data from a django dumpdata using loaddata one column was somehow converted from character varying(100)[] to character varying(100)[][]. How can I collapse the inner array.
Example: previous data
{frank}
uploaded data
{{f,r,a,n,k}}
Solution 1:[1]
Sample Converting Query:
with tb1 as (
select '{{f,r,a,n,k}}'::text[][] as pdata
)
select array_agg(a2.pdata2) from
(
select string_agg(a1.pdata1, '') as pdata2 from
(
select unnest(pdata) as pdata1 from tb1
) a1
) a2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ramin Faracov |
