Thread: Problem with FOR LOOP query

Problem with FOR LOOP query

From
"Greg Quinn"
Date:
I am using EMS's PostGreSQL manager to create a new function using language
SQL and pgSQL

In my function I am trying to declare a variable of type RECORD.

DECLARE curRecord RECORD;

But it gives an error. It also doesn't like my FOR LOOP

FOR curRecord IN SELECT messageid from email_inbox where folderid = $1 LOOP
    EXECUTE sp_deleteemailinboxmessagetodeleteditems(curRecord.messageid);
LOOP;

What I don't understand is the documentation says this is how one declares
your variable and the FOR loop but it doesn't work.

Re: Problem with FOR LOOP query

From
Tom Lane
Date:
"Greg Quinn" <greg@officium.co.za> writes:
> In my function I am trying to declare a variable of type RECORD.
> DECLARE curRecord RECORD;
> But it gives an error.

Worksforme.  You really need to provide a complete example and the
specific error you're getting if you want useful help.

> It also doesn't like my FOR LOOP

> FOR curRecord IN SELECT messageid from email_inbox where folderid = $1 LOOP
>     EXECUTE sp_deleteemailinboxmessagetodeleteditems(curRecord.messageid);
> LOOP;

I think the problem is the last line has to be END LOOP; ... though
again the specific text of the error would have made diagnosis a lot
more certain.

            regards, tom lane