title: Postgresql Functions - Using VARIADIC arguments of text type
body: <p>I am trying to write a function to get the list of objects in schema from Redshift. I have created a dblink from RDS PostgreSQL to Redshift. The query is working just fine when invoked individually, but not working when written inside a function with arguments. I want to pass multiple arguments (schema names), hence I used VARIADIC arguments. The function looks like below -</p>
  
  <pre><code>CREATE FUNCTION f_fetch_tables(VARIADIC list text[]) 
  RETURNS VOID
  AS $$
      DECLARE
          begin_time TIMESTAMP;
          expire_time TIMESTAMP;
      BEGIN   
          /* To fetch the list of all objects from Redshift */
          EXECUTE 'drop table if exists tmp_rs_obj_list;
          create table tmp_rs_obj_list as 
          SELECT * FROM dblink(''rs_link'',$REDSHIFT$ select * from (select schemaname, 
          tablename from pg_tables UNION select schemaname, viewname from pg_views) where schemaname 
          not in (array_to_string($1,'','')) $REDSHIFT$) AS t1 (schema_nm varchar(30), obj_nm varchar(100))' using list;
      END;
    $$
    LANGUAGE plpgsql
  ;
  </code></pre>
  
  <p>The function compiles fine and is created successfully, but I am not able to figure out a way to call it -</p>
  
  <p>Used these calls so far, without any luck -</p>
  
  <ol>
  <li><p>select f_fetch_tables('{public,pg_catalog}')</p>
  
  <p>ERROR: there is no parameter $1
  Where: Error occurred on dblink connection named "unnamed": could not 
  execute query.</p></li>
  <li><p>select * from f_fetch_tables(VARIADIC '{public,pg_catalog}')</p>
  
  <p>ERROR: there is no parameter $1
  Where: Error occurred on dblink connection named "unnamed": could not execute query.</p></li>
  </ol>
  
  <p>Any suggestions would be really helpful.</p>
  
  <p>Thank you,
  Kamlesh</p>