title: how to write to dynamically created table in Redshift procedure
body: <p>I need to write a procedure in Redshift that will write to a table, but the table name comes from the input string. Then I declare a variable that puts together the table name.</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE my_schema.data_test(current "varchar")
      LANGUAGE plpgsql
  AS $$                                                        
  declare new_table varchar(50) = 'new_tab' || '_' || current;
  
  BEGIN 
      select 'somestring' as colname into new_table;
      commit;
  END;
  $$
  </code></pre>
  
  <p>This code runs but it doesn't create a new table, no errors. If I remove the declare statement then it works, creating a table called "new_table". It's just not using the declared variable name. </p>
  
  <p>It's hard to find good examples because Redshift is postgresql and all the postgresql pages say that it only has functions, not procedures. But Redshift procedures were introduced last year and I don't see many examples. </p>