Re: array to rows of it's elements? - Mailing list pgsql-novice

From Celia McInnis
Subject Re: array to rows of it's elements?
Date
Msg-id 20050706164049.M36117@drmath.ca
Whole thread Raw
In response to array to rows of it's elements?  ("Celia McInnis" <celia@drmath.ca>)
List 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)


pgsql-novice by date:

Previous
From:
Date:
Subject: Re: Aliased table names ...oddity?
Next
From:
Date:
Subject: User Defined Note Order Problem