Re: Error when trying to use a FOR loop - Mailing list pgsql-sql

From Tom Lane
Subject Re: Error when trying to use a FOR loop
Date
Msg-id 29387.1153496411@sss.pgh.pa.us
Whole thread Raw
In response to Re: Error when trying to use a FOR loop  ("Kevin Nikiforuk" <Kevin.Nikiforuk@Acrodex.com>)
List pgsql-sql
"Kevin Nikiforuk" <Kevin.Nikiforuk@Acrodex.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


pgsql-sql by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Error when trying to use a FOR loop
Next
From: Tom Lane
Date:
Subject: Re: System catalog table privileges