title: Query without dependencies recursive table
body: <p>I'm trying to select a database registry that does not have dependencies (look at the figure and the result).</p>
  
  <p><img src="https://i.stack.imgur.com/p7hNk.png" alt="TABLE"></p>
  
  <p>RESULT</p>
  
  <p><img src="https://i.stack.imgur.com/JRyDU.png" alt="RESULTADO"></p>
  
  <p>I have tried with the following function:</p>
  
  <pre><code>create or replace function consultar(id integer)
  RETURNS TABLE(cod character varying, nom character varying) as
  $$
  declare
  ids character varying[];
  begin
  ids:=(select array(select distinct tb_plan_p from 
  tb_plan where 
  tb_plan_p is not null order by tb_plane_p));
  
  RETURN QUERY
  select tb_plan_cod, tb_plan_des
  from tb_plan
  where tb_plan_cod &lt;&gt; any(ids) order by tb_plane_cod;
  end;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>I tried first to create an array that contains the cod that have dependencies and then remove those cod from the result
  But I have not got what I want</p>