Re: arrays as parameters to pl/pgsql functions - Mailing list pgsql-general

From Ben
Subject Re: arrays as parameters to pl/pgsql functions
Date
Msg-id Pine.LNX.4.44.0311171412090.7403-100000@localhost.localdomain
Whole thread Raw
In response to arrays as parameters to pl/pgsql functions  ("Julie May" <julie@ccorb.com>)
List pgsql-general
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)



pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: PostgreSQL v7.4 Released
Next
From: Peter Eisentraut
Date:
Subject: SuSE RPMs available for PostgreSQL 7.4