Re: generic way to retrieve array as rowset - Mailing list pgsql-general

From Volkan YAZICI
Subject Re: generic way to retrieve array as rowset
Date
Msg-id 20060103144208.GA569@alamut
Whole thread Raw
In response to generic way to retrieve array as rowset  (SunWuKung <Balazs.Klein@axelero.hu>)
Responses Re: generic way to retrieve array as rowset
List pgsql-general
Hi,

Here's a modified version of A. Kretschmer's answer. This one checks
array_upper() sizes and depending on it, doesn't provide unnecessary
NULL fields. HTH.

SELECT id, val[s.i]
FROM t7
LEFT JOIN
    (SELECT g.s
        FROM generate_series(1,
            (SELECT max(array_upper(val, 1)) FROM t7)) AS g(s)
    ) AS s(i)
    ON (s.i <= array_upper(val, 1));

Query is inspired by the pg_database_config view in newsysview.
(Thanks AndrewSN for pointing out the source.)


Regards.

On Jan 03 12:37, SunWuKung wrote:
> When storing data in an array, like this
>
> id    array
> 1,     {1,2}
> 2,     {10,20}
> 3,     {100,200}
>
> is there a generic way to retrieve them as arowset, like this
>
> id    array_dimension1
> 1    1
> 1     2
> 2     10
> 2     20
>
> By writing something like this:
>
> Select id, explode(array) From foo Where id<3

pgsql-general by date:

Previous
From: Arnaud Lesauvage
Date:
Subject: initdb: invalid locale name
Next
From: Andrew - Supernews
Date:
Subject: Re: POSTGRES DB 3 800 000 rows table, speed up?