title: How to create a VIEW from function with parameters?
body: <p>I have this function in PostgreSQL:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION func1(a integer, b timestamp, c integer[])
    RETURNS SETOF typ_new AS 
  $BODY$
  declare
  begin
      CREATE OR REPLACE VIEW newView as (select * from func2($1,$2,$3));
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE
  </code></pre>
  
  <p><code>func2</code> also returns <code>SETOF typ_new</code> so they are compatible.</p>
  
  <p>When running it I get an error : <code>ERROR:  there is no parameter $1</code>
  if I change the <code>$1</code> to the parameter name <code>a</code> then the error changes to 
  <code>ERROR: column "a" does not exist</code></p>
  
  <p>I also tried dynamic SQL:</p>
  
  <pre><code>    sqlstr ='CREATE OR REPLACE VIEW newView (columns... ) as
                (select * from func2('||$1||','||$2||','||$3||'))';
      execute sqlstr;
  </code></pre>
  
  <p>but it doesn't work because <code>$3</code> is <code>integer[]</code> and <code>||</code> can't work with arrays.</p>
  
  <p>How do I solve this?</p>