Skip site navigation (1) Skip section navigation (2)

converting 1 dimensional array to 2 dimensional array

From: Nicholas Wilson <nwilson5(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: converting 1 dimensional array to 2 dimensional array
Date: 2012-03-12 20:31:42
Message-ID: CABgBcYO=PCP_pP+_hk_ZYQ6gACrQ7fzJe8__xfWg3OCX5wGSoA@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi, need help with some syntax.

Currently we have a column of type text[]. It is a 1 dimensional array of
text values. Each of them we have formatted in such a way that it can be
split into two values. We are trying to convert it into a two dimensional
array but are unsure how to do that.

i.e. converting:
{a^^val1, b^^val2, c^^val3}
to
{{a,val1}, {b,val2}, {c,val3}}

I can do
Select array(select '{"' || replace(unnest(col1), '^^', '","') || '"}')
from table;

But that still gives me one dimensional text array. I can't cast it to
text[] because there are no array of arrays. How do I get this into a 2
dimensional array?

Responses

pgsql-novice by date

Next:From: JohnDate: 2012-03-13 05:01:50
Subject: Warning console code page (437) differs from Window code page (1252)
Previous:From: Gavin FlowerDate: 2012-03-10 19:38:24
Subject: Re: When to choose putting logic into PL/pgSQL and when to use an app server

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group