title: Dynamic table names by date
body: <p>So I have tables that I need to generate nightly. As an example I have tables such as foo_01jan16, foo_02jan2016, foo_03jan2016, etc. Additionally I reference these table(s) in other queries that I run daily. However, find and replace seems inefficient. What I want to do is automate this process. I want to do something like:</p>
  
  <pre><code>    CREATE OR REPLACE FUNCTION table_date() RETURNS text AS $$
              SELECT 'foo_'||to_char(current_timestamp, 'DDMONYY') AS result
      $ LANGUAGE SQL;
  </code></pre>
  
  <p>Then in query I can reference <code>table_date()</code>? i.e.</p>
  
  <pre><code>    CREATE TABLE table_date() AS
      SELECT * FROM base_table WHERE date &lt;= current_date;
  
      SELECT * FROM table_date() LIMIT 10;
  </code></pre>
  
  <p>Something like that. I am using postgreSQL 8.2. </p>
  
  <p>Thanks</p>