i have that working code, but i need to convert it to function with dynamic attribute tid=1645
where number 1645 will always change.
with recursive r as (
select tid, boss from titles where tid=1645
union
select titles.tid, titles.boss from titles join r on titles.tid = r.boss
)
select * from r
Now, i have the same:
DROP FUNCTION bosses_of_rsd_tids(integer);
CREATE OR REPLACE FUNCTION public.bosses_of_rsd_tids(rsd_tid int)
RETURNS table (c_tid int, c_boss int)
LANGUAGE plpgsql
AS $function$
begin
with recursive r as (
select tid, boss from titles where tid=rsd_tid
union
select titles.tid, titles.boss from titles join r on titles.boss = r.tid
)
select c_tid, c_boss;
end;
$function$
;
As a result i need table of results... I tried to return select c_tid, c_boss;
but have error: error near return