From: Josh Berkus <josh@agliodbs.com>
To: Peter Atkins <peter.atkins@NXCD.com>
To: pgsql-sql@postgresql.org
Subject: Re: Passing array to PL/SQL and looping
Date: Thu, 26 Sep 2002 18:20:08 -0700
Message-ID: <200209261820.08106.josh@agliodbs.com> (raw)
In-Reply-To: <1CAD483B723BD611B0C10090274FF068554860@NXCDMAIL>
References: <1CAD483B723BD611B0C10090274FF068554860@NXCDMAIL>
Peter,
> I'm a newbie to PL/SQL and need help badly. I'm trying to pass my array of
> id's to the function and then loop through until the array is empty. I know
> there must be atleast five things I'm doing wrong.
Simplified example:
CREATE FUNCTION test_array (
INT[] )
RETURNS INT AS '
DECLARE id_array ALIAS for $1;
count_it INT;
BEGIN
count_it := 1;
WHILE id_array[count_it] LOOP
count_it := count_it + 1;
END LOOP;
RETURN (count_it - 1);
END;'
LANGUAGE 'plpgsql';
returns the number of elements in the supplied array.
--
Josh Berkus
josh@agliodbs.com
Aglio Database Solutions
San Francisco
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-sql@postgresql.org
Cc: josh@agliodbs.com, peter.atkins@NXCD.com
Subject: Re: Passing array to PL/SQL and looping
In-Reply-To: <200209261820.08106.josh@agliodbs.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