title: PostgreSQL - use date constant in c function
body: <p>I am trying to rewrite the following SQL function into c equivalent (trying to make it a little bit faster):</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION dat2(time_key integer)
    RETURNS date AS
  $BODY$
  BEGIN
          RETURN case when time_key &gt; 0 then '2006-12-31'::date + time_key end as result;
  END;
  $BODY$
    LANGUAGE plpgsql IMMUTABLE STRICT
    COST 100;
  </code></pre>
  
  <p>I thought I can modify existing <code>date</code>+<code>int4</code> operator and do something like:</p>
  
  <pre><code>#include "postgres.h"
  #include "fmgr.h"
  #include "utils/date.h"
  
  #ifdef PG_MODULE_MAGIC
  PG_MODULE_MAGIC;
  #endif
  
  PG_FUNCTION_INFO_V1(dwd);
  
  Datum
  dwd(PG_FUNCTION_ARGS)
  {
       /* DateADT     dateVal = PG_GETARG_DATEADT(0); */
       DateADT     dateVal = PG_GETARG_DATEADT(2006-12-31);
       int32       days = PG_GETARG_INT32(0);
  
       PG_RETURN_DATEADT(dateVal + days);
  }
  </code></pre>
  
  <p>If I compile my function and turn it into <code>.so</code> I can create <code>dwd</code> function in PostgreSQL:</p>
  
  <pre><code>create or replace function dwd(int) returns date as 
  '/usr/lib/postgresql/9.3/lib/dwd', 'dwd'
    language c
    cost 1;
  </code></pre>
  
  <p>I get <code>2000-01-01</code> for <code>select dwd(0);</code>, but I expected <code>2006-12-31</code>. Apparently there is problem in <code>DateADT dateVal = PG_GETARG_DATEADT(2006-12-31);</code>. </p>
  
  <p>How do I define date constant in this c function? </p>