From: Erwin Brandstetter <brsaweda@gmail.com>
To: pgsql-admin@postgresql.org
Subject: Re: get the array content whis the select clause
Date: Wed, 06 Jun 2007 08:48:35 -0700
Message-ID: <1181144915.299010.239270@p77g2000hsh.googlegroups.com> (raw)
In-Reply-To: <DFF9CC68-0B19-4464-B998-626911BF4360@skype.net>
References: <46647A79.3020401@eurofer.be>
<DFF9CC68-0B19-4464-B998-626911BF4360@skype.net>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: brsaweda@gmail.com
Subject: Re: get the array content whis the select clause
In-Reply-To: <1181144915.299010.239270@p77g2000hsh.googlegroups.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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