Re: [Q] parsing out String array

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [Q] parsing out String array
Date: 2009-08-16 11:06:07
Message-ID: 20090816110607.GU5407@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Aug 16, 2009 at 05:55:08AM -0400, toreason(at)fastmail(dot)fm wrote:
> Thank you for your recommendation
> I was able to get this to work
>
> select ('{{A,B,C},{D,E,F}}'::text[][])[i][j] from
> generate_series(1, array_upper('{{A,B,C},{D,E,F}}'::text[][], 1)) i
> cross join
> generate_series(1, array_upper('{{A,B,C},{D,E,F}}'::text[][], 2)) j

I've just noticed that you mentioned using 8.4 previously; there's a new
function called unnest in 8.4 that does the above. In your example it
would be:

SELECT unnest('{{A,B,C},{D,E,F}}'::text[]);

and you'd get back your six rows. It appears to do the correct thing
with arrays of higher dimensionality to me, but I only tried up to five.

--
Sam http://samason.me.uk/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thom Brown 2009-08-16 11:07:27 Generating random unique alphanumeric IDs
Previous Message toreason 2009-08-16 09:55:08 Re: [Q] parsing out String array