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

From Petr Bravenec
Subject Re: return next in recursive function
Date
Msg-id 3F7D07B4.3050507@solartec.cz
Whole thread Raw
In response to Re: return next in recursive function  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Responses Re: return next in recursive function
List pgsql-general
Stephan Szabo napsal(a):

>>create or replace function foo (integer)
>>          returns setof foo as '
>>    declare pid     alias for $1;
>>    declare rec     RECORD;
>>    BEGIN
>>    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);
>>
>>
>
>Shouldn't you be looping over these results in order to return them,
>something like
> FOR rec2 in select * from foo(rec.uid) LOOP
>  return next rec2;
> END LOOP;
>
>Otherwise, why should the results from the other call become results from
>your call (what if you want to process them and not return all of them, or
>what if it's a function with a different type?)
>
>
>
Yes, I understand but I expect that the Postgres will try to do what I
wrote.
In the case of datatype michmach I would expect that the Postgres returns
error as it do in case of
select a:int4 from table1
union all
select b:text from table2;

How Postgres recognizes how was the function called?
How can Postgres recognize the the function is called recursivelly?
I can insert selected rows into temporary table and return them
in the highest level of recursion when I recognized it.


--

email: pbravenec@solartec.cz
telefon: 777 566 384
icq: 227051816





pgsql-general by date:

Previous
From: Scott Cain
Date:
Subject: Re: migrate from postgres to mysql
Next
From: Dennis Gearon
Date:
Subject: anyone give me some good liniks to ...