Re: returning an array as a list fo single-column rows?

From: Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: returning an array as a list fo single-column rows?
Date: 2007-12-23 21:22:05
Message-ID: 20071223212205.GA15367@apartia.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Dec 23, 2007 at 10:19:26PM +0100, Pavel Stehule wrote:
> Hello
>
> try
>
> create or replace function unpack(anyarray)
> returns setof anyelement as $$
> select $1[i]
> from generate_series(array_lower($1,1), array_upper($1,1)) g(i);
> $$ language sql;
>
> postgres=# select * from unpack(array[1,2,3,4]);
> unpack
> --------
> 1
> 2
> 3
> 4
> (4 rows)

Beautiful. Thank you.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Pavel Stehule 2007-12-23 21:27:09 Re: returning an array as a list fo single-column rows?
Previous Message Pavel Stehule 2007-12-23 21:19:26 Re: returning an array as a list fo single-column rows?