Re: Using unnest function on multi-dimensional array.

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Nimesh Satam <nimesh(dot)zedo(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org, Nimesh Satam <nimesh(dot)satam(at)gmail(dot)com>
Subject: Re: Using unnest function on multi-dimensional array.
Date: 2009-10-12 08:57:34
Message-ID: 162867790910120157y348af215id5625fd1765ea5ad@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello

2009/10/12 Nimesh Satam <nimesh(dot)zedo(at)gmail(dot)com>:
> Hi,
>
> Can anybody highlight how to use unnest function from postgres 8.4 on
> multi-dimensional array?
>
> Below is the sample table structure:
>
> Table "public.multi_array_test"
>  Column  |   Type   | Modifiers
> ---------+----------+-----------
>  id      | integer  |
>  user_id | bigint[] |
>
> Sample data:
>
>   1 | {{3567559397,0},{3020933367,1},{2479094216,2},{3310282955,3}}
>
> Regards,
> Nimesh.
>

use generate_subscripts

postgres=#
create or replace function unnest2(anyarray)
returns setof anyelement as $$
select $1[i][j]
from generate_subscripts($1,1) g1(i),
generate_subscripts($1,2) g2(j);
$$ language sql immutable;

postgres=# select * from unnest2(array[[1,2],[3,4]]);
unnest2
---------
1
2
3
4
(4 rows)

regards
Pavel Stehule

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Michal Vitecek 2009-10-12 09:23:39 Re: updating a row in a table with only one row
Previous Message Nimesh Satam 2009-10-12 08:47:15 Using unnest function on multi-dimensional array.