pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedget the array content whis the select clause
4+ messages / 3 participants
[nested] [flat]
* get the array content whis the select clause
@ 2007-06-04 20:47 De Leeuw Guy <G.De_Leeuw@eurofer.be>
0 siblings, 1 reply; 4+ messages in thread
From: De Leeuw Guy @ 2007-06-04 20:47 UTC (permalink / raw)
To: pgsql-admin
Hello all
It is possible to return the content of an int array [] with a select
clause ?
Thanks in advance for your respons
Guy
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: get the array content whis the select clause
@ 2007-06-05 10:13 Kristo Kaiv <kristo.kaiv@skype.net>
parent: De Leeuw Guy <G.De_Leeuw@eurofer.be>
0 siblings, 2 replies; 4+ messages in thread
From: Kristo Kaiv @ 2007-06-05 10:13 UTC (permalink / raw)
To: De Leeuw Guy <G.De_Leeuw@eurofer.be>; +Cc: pgsql-admin
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
------
5
6
7
8
(4 rows)
BR,
Kristo
On 04.06.2007, at 23:47, De Leeuw Guy wrote:
> Hello all
>
> It is possible to return the content of an int array [] with a select
> clause ?
>
> Thanks in advance for your respons
>
> Guy
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that
> your
> message can get through to the mailing list cleanly
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: get the array content whis the select clause
@ 2007-06-05 20:50 De Leeuw Guy <G.De_Leeuw@eurofer.be>
parent: Kristo Kaiv <kristo.kaiv@skype.net>
1 sibling, 0 replies; 4+ messages in thread
From: De Leeuw Guy @ 2007-06-05 20:50 UTC (permalink / raw)
To: Kristo Kaiv <kristo.kaiv@skype.net>; +Cc: pgsql-admin
Great !!!
Many thanks Kristo, it's just what I need
Guy
Kristo Kaiv a écrit :
> 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
> ------
> 5
> 6
> 7
> 8
> (4 rows)
>
> BR,
> Kristo
>
> On 04.06.2007, at 23:47, De Leeuw Guy wrote:
>
>> Hello all
>>
>> It is possible to return the content of an int array [] with a select
>> clause ?
>>
>> Thanks in advance for your respons
>>
>> Guy
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 1: if posting/reading through Usenet, please send an appropriate
>> subscribe-nomail command to majordomo@postgresql.org so that your
>> message can get through to the mailing list cleanly
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: get the array content whis the select clause
@ 2007-06-06 15:48 Erwin Brandstetter <brsaweda@gmail.com>
parent: Kristo Kaiv <kristo.kaiv@skype.net>
1 sibling, 0 replies; 4+ messages in thread
From: Erwin Brandstetter @ 2007-06-06 15:48 UTC (permalink / raw)
To: pgsql-admin
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
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2007-06-06 15:48 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-06-04 20:47 get the array content whis the select clause De Leeuw Guy <G.De_Leeuw@eurofer.be>
2007-06-05 10:13 ` Kristo Kaiv <kristo.kaiv@skype.net>
2007-06-05 20:50 ` De Leeuw Guy <G.De_Leeuw@eurofer.be>
2007-06-06 15:48 ` Erwin Brandstetter <brsaweda@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox