Обсуждение: array to rows of it's elements?

Поиск
Список
Период
Сортировка

array to rows of it's elements?

От
"Celia McInnis"
Дата:
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

Re: array to rows of it's elements?

От
"Celia McInnis"
Дата:
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)