Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 63A1247610D for ; Thu, 26 Sep 2002 21:21:25 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 73FF0476083 for ; Thu, 26 Sep 2002 21:21:23 -0400 (EDT) Received: from [216.135.165.74] (HELO lazarus) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP-TLS id 1731309; Thu, 26 Sep 2002 18:21:27 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Peter Atkins , pgsql-sql@postgresql.org Subject: Re: Passing array to PL/SQL and looping Date: Thu, 26 Sep 2002 18:20:08 -0700 X-Mailer: KMail [version 1.4] References: <1CAD483B723BD611B0C10090274FF068554860@NXCDMAIL> In-Reply-To: <1CAD483B723BD611B0C10090274FF068554860@NXCDMAIL> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200209261820.08106.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/349 X-Sequence-Number: 9626 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 kn= ow > there must be atleast five things I'm doing wrong. Simplified example: CREATE FUNCTION test_array ( INT[] )=20 RETURNS INT AS ' DECLARE id_array ALIAS for $1; count_it INT; BEGIN count_it :=3D 1; WHILE id_array[count_it] LOOP count_it :=3D count_it + 1; END LOOP; RETURN (count_it - 1); END;' LANGUAGE 'plpgsql'; returns the number of elements in the supplied array. --=20 Josh Berkus josh@agliodbs.com Aglio Database Solutions San Francisco