Re: Passing array to PL/SQL and looping

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Peter Atkins <peter(dot)atkins(at)NXCD(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Passing array to PL/SQL and looping
Date: 2002-09-27 01:20:08
Message-ID: 200209261820.08106.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)agliodbs(dot)com
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-09-27 03:15:33 Re: FW: query problem "server sent binary data ... without
Previous Message Jordan Reiter 2002-09-27 00:17:35 Re: Case Sensitive "WHERE" Clauses?