title: How to automatically create a table on a predefined interval (e.g. month) using current_date()
body: <p>I would like to automatically create a table, in my postgresql db, every month using stored data. Every time the query runs I would like the table name to change dynamically (e.g table_JAN2018, table_FEB2018, table_MAR2018 etc) so as a new table is created with the new data of that month while the old tables remain intact.</p>
  
  <p>After researching, I found that I can achieve this (?) as described in the link below: <a href="https://stackoverflow.com/questions/10705616/table-name-as-a-postgresql-function-parameter">Table name as a PostgreSQL function parameter</a></p>
  
  <p>So I tried, in same fashion, the code below:</p>
  
  <pre><code>CREATE FUNCTION table_Jan2018() RETURNS void as 
  $func$
  BEGIN 
  EXECUTE
  
  'create table' || to_char(current_date, '%b/%Y'|| 'as select * from
  (
  select
  id,product, client, purchase_date, sales_status,
  case when complete_transaction_date is null then cast(purchase_date as date)
  when verified  is not null  then cast(complete_transaction_date  as date)
  end as purchase
  from clients
  where sales_status in ('state1','state2')
  and test=false
  )
  where purchase&gt;=(current_date - interval '30' day)';
  end;
  </code></pre>
  
  <p>However, what i get is the following error message in presto:
  "no viable alternative at input 'CREATE FUNCTION' "</p>
  
  <p>Is the above function suitable in order to change dynamically the table name as I need? Is there another way to achieve what i want?</p>
  
  <p>Thank you in advance!!</p>