Re: generic way to retrieve array as rowset

From: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
To: SunWuKung <Balazs(dot)Klein(at)axelero(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: generic way to retrieve array as rowset
Date: 2006-01-03 14:42:08
Message-ID: 20060103144208.GA569@alamut
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arnaud Lesauvage 2006-01-03 14:43:08 initdb: invalid locale name
Previous Message Manfred Koizar 2006-01-03 14:38:03 Re: POSTGRES DB 3 800 000 rows table, speed up?