Re: arrays as parameters to pl/pgsql functions

From: "Julie May" <julie(at)ccorb(dot)com>
To: "Ben" <bench(at)silentmedia(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: arrays as parameters to pl/pgsql functions
Date: 2003-11-17 22:25:39
Message-ID: 042801c3ad59$bb769030$687ba8c0@impsu.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you Ben, that worked.

----- Original Message -----
From: "Ben" <bench(at)silentmedia(dot)com>
To: "Julie May" <julie(at)ccorb(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Sent: Monday, November 17, 2003 3:17 PM
Subject: Re: [GENERAL] arrays as parameters to pl/pgsql functions

> 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)
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2003-11-17 22:58:34 tracking down temp files
Previous Message Marc G. Fournier 2003-11-17 22:22:53 Re: PostgreSQL v7.4 Released