Re: array to rows of it's elements?

From: "Celia McInnis" <celia(at)drmath(dot)ca>
To: "Celia McInnis" <celia(at)drmath(dot)ca>, pgsql-novice(at)postgresql(dot)org
Subject: Re: array to rows of it's elements?
Date: 2005-07-06 16:49:53
Message-ID: 20050706164049.M36117@drmath.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

This is the best that I can do with what I currenty know, so if you have a
better/faster solution, please send it my way:

CREATE OR REPLACE FUNCTION array_to_rows(myarray ANYARRAY) RETURNS SETOF
ANYELEMENT AS $$
BEGIN
FOR j IN 1..ARRAY_UPPER(myarray,1) LOOP
RETURN NEXT myarray[j];
END LOOP;
RETURN;
END;
$$ LANGUAGE 'plpgsql';

which I may then call like:

SELECT * FROM arrayto_rows(somearray);

Thanks
Celia McInnis

On Wed, 6 Jul 2005 09:37:10 -0500, Celia McInnis wrote
> Is there a function which will return the elements of an array as
> rows of entries? What I'd like in the 1 dimensional array case is
> something like:
>
> select array-to-rows(ARRAY[1,2,3]);
>
> giving
>
> 1
> 2
> 3
> (3 rows)
>
> Thanks,
> Celia McInnis
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
Open WebMail Project (http://openwebmail.org)

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message operationsengineer1 2005-07-06 16:56:13 User Defined Note Order Problem
Previous Message operationsengineer1 2005-07-06 16:01:56 Re: Aliased table names ...oddity?