Re: return next in recursive function - Mailing list pgsql-general

From Tom Lane
Subject Re: return next in recursive function
Date
Msg-id 27424.1065107531@sss.pgh.pa.us
Whole thread Raw
In response to return next in recursive function  (Petr Bravenec <pbravenec@solartec.cz>)
List pgsql-general
Petr Bravenec <pbravenec@solartec.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

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: return next in recursive function
Next
From: Robert Treat
Date:
Subject: Re: Adding missing FROM-clause entry in subquery