Re: return next in recursive function

From: Petr Bravenec <pbravenec(at)solartec(dot)cz>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: return next in recursive function
Date: 2003-10-03 05:23:00
Message-ID: 3F7D07B4.3050507@solartec.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)solartec(dot)cz
telefon: 777 566 384
icq: 227051816

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dennis Gearon 2003-10-03 05:43:23 anyone give me some good liniks to ...
Previous Message Scott Cain 2003-10-02 20:31:41 Re: migrate from postgres to mysql