title: SQL state: 42601 syntax error at or near "11"
body: <p>I have a table <code>address_all</code> and it is inherited by several address tables. <code>address_history</code> inherits from parent table <code>history_all</code> and keeps current address information. I am creating new table which inherits <code>address_all</code> table and copies information from <code>address_history</code> to new table.</p>
  
  <p>My stored procedure is like this below. I am having some error when I call it. To better explain error I am using line number.</p>
  
  <pre><code>1  CREATE OR REPLACE FUNCTION somefunc()
  2  RETURNS void AS
  3  $BODY$
  4  DECLARE
  5   year_id INTEGER;
  6   month_id INTEGER;
  7   week_id INTEGER;
  8   addresstablename text; 
  9   backupdays text;
  10 BEGIN
  11  week_id := EXTRACT(DAY FROM TIMESTAMP 'now()');
  12  month_id := EXTRACT(MONTH FROM TIMESTAMP 'now()');
  13  year_id := EXTRACT(YEAR FROM TIMESTAMP 'now()');
  14  addresstablename := 'address_history_' || week_id || '_' || month_id || '_' || year_id;
  15  backupdays:= date_trunc('hour',CURRENT_TIMESTAMP - interval '7 days');
  16  EXECUTE 'create table ' || addresstablename || '() INHERITS (address_all)';
  17  EXECUTE 'insert into ' || addresstablename || ' select * from address_history where address_timestamp &gt;= ' || backupdays || ''; --AS timestamp without time zone);  
  18 END;
  19 $BODY$
  20 LANGUAGE 'plpgsql' VOLATILE;
  </code></pre>
  
  <p>When I run:</p>
  
  <pre><code>select somefunc()
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>ERROR:  syntax error at or near "12"
  LINE 1: ...story where address_timestamp &gt;= 2012-07-31 12:00:00-0...
                                                           ^
  QUERY:  insert into address_history_7_8_2012 select * from address_history where address_timestamp &gt;= 2012-07-31 12:00:00-04
  CONTEXT:  PL/pgSQL function "somefunc" line 14 at EXECUTE statement
  
   ********** Error **********
  
  ERROR: syntax error at or near "12"
  SQL state: 42601
  Context: PL/pgSQL function "somefunc" line 14 at EXECUTE statement
  </code></pre>