Home > OS >  Postgres: Convert `character varying[]` to string
Postgres: Convert `character varying[]` to string

Time:04-15

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}}

CodePudding user response:

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 
  • Related