title: postgres functions with parameters and dblink
body: <p>I ask for your help with a function to which I need to send search parameters. But the problem is that the function is executed through a DBlink, and I need to pass 2 values as a search parameter, and when executing it does not send the values.</p>
  
  <p>This is the function without dblink:</p>
  
  <hr>
  
  <pre><code>`CREATE OR REPLACE FUNCTION sp_get_afil(i_pers_codigo VARCHAR, i_empr_codigo 
   VARCHAR) RETURNS VARCHAR AS $$
   DECLARE
      v_pers_codigo VARCHAR;
   BEGIN
      select ro.pers_codigo
      into v_pers_codigo
      from unv_roles_personas ro, unv_personas p1, unv_personas p
      where ro.rope_vigente = 'S'
      and ro.empr_codigo = p1.empr_codigo
      and ro.tiro_codigo = 'AFIL'
      and ro.pers_codigo = p1.pers_codigo
      and p1.empr_codigo = p.empr_codigo
      and p1.pers_estado_cae = p.pers_estado_cae
      and p1.pers_numero_cae = p.pers_numero_cae
      and p.empr_codigo = i_empr_codigo
      and p.pers_codigo = i_pers_codigo;
  
      RETURN v_pers_codigo;
  
  END;
  $$ LANGUAGE plpgsql;`
  </code></pre>
  
  <hr>
  
  <p>It works without problems, and here the same function but with dblink, which does not work:</p>
  
  <hr>
  
  <pre><code>`CREATE OR REPLACE FUNCTION sp_get_afil(i_pers_codigo VARCHAR, i_empr_codigo 
   VARCHAR) RETURNS VARCHAR AS $$
   DECLARE
      v_pers_codigo VARCHAR;
      v_empr_codigo VARCHAR;
      vr_pers_codigo VARCHAR;
  BEGIN
      select t1.rop_codigo
      into vr_pers_codigo
      from dblink('dbname = usuarios host=100.1.1.138 port=5432 ',
                  'select ro.pers_codigo
                  from unv_roles_personas ro, unv_personas p1, unv_personas p
                  where ro.rope_vigente = ''S''
                  and ro.empr_codigo = p1.empr_codigo
                  and ro.tiro_codigo = ''AFIL''
                  and ro.pers_codigo = p1.pers_codigo
                  and p1.empr_codigo = p.empr_codigo
                  and p1.pers_estado_cae = p.pers_estado_cae
                  and p1.pers_numero_cae = p.pers_numero_cae
                  and p.empr_codigo = '||quote_literal ($1)||'
                  and p.pers_codigo = '||quote_literal ($2)||'')
       as t1 (rop_codigo character varying);
  
       RETURN vr_pers_codigo;
  
   END;
   $$ LANGUAGE plpgsql;`
  </code></pre>
  
  <hr>
  
  <p>When executing it, it returns a null value and this does not generate the view I need. I'm doing badly, I've investigated, but I'm already in a deadlock.</p>