From: | CSN <cool_screen_name90001(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: array iteration and zeros |
Date: | 2003-11-23 19:38:42 |
Message-ID: | 20031123193842.66615.qmail@web40609.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
How about when there are zeros in the array? Test for
NULL or something?
CSN
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
On Mon, 17 Nov 2003, Julie May wrote:
> Is it possible to use an array as a parameter to a
pl/pgsql function. I am
> running version 7.3 and don't have the time right
now to upgrade.If it is
> possible, how do you iterate through the array? For
example:
CREATE or REPLACE FUNCTION foo(integer[]) RETURNS int
AS
'DECLARE
a alias for $1;
index integer := 1;
total integer := 0;
BEGIN
WHILE a[index] > 0
LOOP
total := total + a[index];
index := index + 1;
END LOOP;
RETURN total;
END;
' LANGUAGE 'plpgsql';
test=> select foo('{1,2}');
foo
-----
3
(1 row)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Date: Sat, 22 Nov 2003 13:03:02 -0800
From: Ben <bench(at)silentmedia(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: array iteration?
Message-ID: <1069534981(dot)1639(dot)368(dot)camel(at)purple>
Yep.
http://archives.postgresql.org/pgsql-general/2003-11/msg00852.php
On Sat, 2003-11-22 at 12:44, CSN wrote:
> Is it possible to iterate over an array in plpgsql?
> Something like:
>
> function insert_stuff (rel_ids int[])
> ...
>
> foreach rel_ids as id
> insert into table (rel_id, val)
> values (id, 5);
>
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Gaetano Mendola | 2003-11-23 19:54:54 | Re: First generic/redhatish RPM's uploaded to ftp.postgresql.org. |
Previous Message | Gaetano Mendola | 2003-11-23 19:33:12 | Re: First generic/redhatish RPM's uploaded to ftp.postgresql.org. |