Re: get the array content whis the select clause
От
Erwin Brandstetter
Тема
Re: get the array content whis the select clause
Дата
Msg-id
1181144915.299010.239270@p77g2000hsh.googlegroups.com
Ответ на
Re: get the array content whis the select clause (Kristo Kaiv)
Список
Дерево обсуждения
get the array content whis the select clause De Leeuw Guy <G.De_Leeuw@eurofer.be>
Re: get the array content whis the select clause Kristo Kaiv <kristo.kaiv@skype.net>
Re: get the array content whis the select clause Erwin Brandstetter <brsaweda@gmail.com>
Re: get the array content whis the select clause De Leeuw Guy <G.De_Leeuw@eurofer.be>
On Jun 5, 12:13 pm, kristo.k...@skype.net (Kristo Kaiv) wrote:
> i guess this what you meant:
> (not a nice solution though) writing a function that returns the set
> would be a better idea
>
> create table testintarr (iarr int[]);
> insert into testintarr values ('5,6,7,8');
>
> test=# select iarr[idx] from (select iarr, generate_series(array_lower
> (iarr,1), array_upper(iarr,1)) as idx from testintarr) asdf;
> iarr
Function would look like this:
CREATE OR REPLACE FUNCTION f_intarr_to_set(integer[])
RETURNS SETOF integer AS
$BODY$
BEGIN
FOR i IN array_lower($1,1) .. array_upper($1,1) LOOP
RETURN NEXT $1[i];
END LOOP;
END;
$BODY$
LANGUAGE 'plpgsql';
SELECT * FROM f_intarr_to_set('{1,3,5,7,9,321}');
But I think I like Kristo�s query even better. :)
Regards
Erwin
В списке pgsql-admin по дате отправления
От: Igor Neyman
Дата: