I have a recursive method defined below:
with recursive temp(id, s, r, e) as (
select *
from rel
where rel_to_id = <parameter from sql query>
union all
select *
from temp P
inner join relationship C on P.r = C.s
)
and I need to call this on each row returned from an SQL query with a column value defined in the recursive query (marked as )
I dont really want to call X queries through python which slows things down, there must be a way to do it in sql. I tried to write a function in plpgsql but I am having trouble defining the return type setof TABLE and taking the union of it each time.
I’m not sure I fully understand the problem, is your issue to call your recursive function on more than 1 initial value, as per the values returned by your ?
In that case, could you just create your initial table at once with all required values, and then recurse through it? Something like this: