Re: passing array as argument and returning an array in - Mailing list pgsql-general

From Jenny Zhang
Subject Re: passing array as argument and returning an array in
Date
Msg-id 1071617841.10925.5.camel@ibm-a.pdx.osdl.net
Whole thread Raw
In response to passing array as argument and returning an array in plpgsql  ("K. Deepa" <kdeepa@midascomm.com>)
Responses Re: passing array as argument and returning an array in  (Rajesh Kumar Mallah <mallah@trade-india.com>)
List pgsql-general
I got this when I was searching for something else.  I will forward this
to you.
http://archives.postgresql.org/pgsql-general/2003-11/msg00852.php
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)
On Tue, 2003-12-16 at 03:25, K. Deepa wrote:
> Hi all,
>        I am using postgresql7.4. How to handle arrays in plpgsql. How can
> I pass an array. Is it possible to retrieve values from an array by
> indexing it like
>
> argument : '{1,2,3}'
> Return value : varchar array
>
> Variables :
> ---------
>
> a alias for $1
> b _varchar
>
> Usage :
> -----
>
> b[1] = a[1];
> b[2] = a[2];
>
> return b;
>
> Is it possible.
>
> TIA,
--
Jenny Zhang
Open Source Development Lab
12725 SW Millikan Way, Suite 400
Beaverton, OR 97005
(503)626-2455 ext 31



pgsql-general by date:

Previous
From: Joe Conway
Date:
Subject: Re: functions returning sets
Next
From: Jenny Zhang
Date:
Subject: update slows down in pl/pgsql function