Re: Error when trying to use a FOR loop

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kevin Nikiforuk" <Kevin(dot)Nikiforuk(at)Acrodex(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Error when trying to use a FOR loop
Date: 2006-07-21 15:40:11
Message-ID: 29387.1153496411@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Kevin Nikiforuk" <Kevin(dot)Nikiforuk(at)Acrodex(dot)com> writes:
> CREATE OR REPLACE FUNCTION rgio() RETURNS integer as $$
> BEGIN
> DECLARE lv RECORD;
> FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP
> SELECT ldev FROM ldevrg WHERE ldevrg='$lv';
> END LOOP;
> RETURN 1;
> END;
> $$ LANGUAGE plpgsql;

You've got a small error in the layout: the DECLARE part goes before
BEGIN not after. Swap the first two lines of the function.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2006-07-21 16:01:44 Re: Error when trying to use a FOR loop
Previous Message A. Kretschmer 2006-07-21 15:39:20 Re: Error when trying to use a FOR loop