title: How convert recursive to function in plpgsql?
body: <p>i have that working code, but i need to convert it to function with dynamic attribute <code>tid=1645</code> where number 1645 will always change.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Now, i have the same:</p>
  
  <pre><code>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$
  ;
  </code></pre>
  
  <p>As a result i need table of results... I tried to <code>return select c_tid, c_boss;</code> but have error: error near return</p>