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:
CREATE OR REPLACE FUNCTION table_date() RETURNS text AS $$
SELECT 'foo_'||to_char(current_timestamp, 'DDMONYY') AS result
$ LANGUAGE SQL;
Then in query I can reference table_date()
? i.e.
CREATE TABLE table_date() AS
SELECT * FROM base_table WHERE date <= current_date;
SELECT * FROM table_date() LIMIT 10;
Something like that. I am using postgreSQL 8.2.
Thanks