title: PostgreSQL: ERROR operator does not exist: || character varying
body: <p>I need to check the condition within function using string_agg() function and need to assign it to variable. After assigning I need to execute the variable with value.  </p>
  
  <p><strong>Example</strong>:</p>
  
  <pre><code>create or replace function funct1(a int,b varchar)
  returns void as
  $$
  declare
          wrclause varchar := '';
          sqlq varchar ;
          t varchar;
  begin
       IF (b IS NOT NULL ) THEN 
          wrclause := 'AND b IN ('|| b || ')';
       END IF;
  
  
       sqlq := string_agg('select *, abcd as "D" from ' ||table_namess,' Union all ') as namess
       from tablescollection2 ud
       inner join INFORMATION_SCHEMA.Tables so on ud.table_namess = so.Table_name
       WHERE cola NOT IN (SELECT cola FROM tablet WHERE colb = || a  ||) || wrclause; /* Error occurred here at  = || a */
  
       raise info '%',sqlq;
  
       execute sqlq into t;
  
       raise info '%',t;
  end;
  $$
  language plpgsql;
  </code></pre>
  
  <p><strong>Calling Function</strong>:</p>
  
  <pre><code>select funct1(1,'1,2,3');
  </code></pre>
  
  <p><strong>Error</strong>:</p>
  
  <pre><code>ERROR:  operator does not exist: || integer
  </code></pre>