Re: return next in recursive function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Petr Bravenec <pbravenec(at)solartec(dot)cz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: return next in recursive function
Date: 2003-10-02 15:12:11
Message-ID: 27424.1065107531@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Petr Bravenec <pbravenec(at)solartec(dot)cz> writes:
> FOR rec in select * from foo
> where foo.pid=pid LOOP
> return next rec;
> raise warning ''uid=% pid=%'',rec.uid,rec.pid;
> select into rec * from foo (rec.uid);
> END LOOP;
> return null;

This is simply throwing away the results of the recursive call.
If you are trying to append those results to the outer call's
results, maybe do this:

FOR rec in select * from foo
where foo.pid=pid LOOP
return next rec;
raise warning ''uid=% pid=%'',rec.uid,rec.pid;
FOR rec2 in select * from foo (rec.uid) LOOP
return next rec2;
END LOOP;
END LOOP;
return null;

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2003-10-02 16:41:03 Re: Adding missing FROM-clause entry in subquery
Previous Message Stephan Szabo 2003-10-02 15:03:00 Re: return next in recursive function