title: Create a trigger in C on PostgreSQL 9
body: <p>I have a PostgreSQL 9.0 server on Ubuntu 10.04, and I try to create an trigger in C code, following the next links:</p>
  
  <p><a href="http://www.postgresql.org/docs/9.0/static/trigger-example.html" rel="nofollow">Documentation</a>, <a href="http://www.postgresql.org/docs/9.0/static/xfunc-c.html#DFUNC" rel="nofollow">Compile</a></p>
  
  <p>For the time being, my code should show only the value of the column in a record (and return the "edited" record):</p>
  
  <pre><code>#include "postgres.h"
  #include "executor/spi.h"
  #include "commands/trigger.h"
  
  #ifdef PG_MODULE_MAGIC
  PG_MODULE_MAGIC;
  #endif
  
  extern Datum trigger_test(PG_FUNCTION_ARGS);
  
  PG_FUNCTION_INFO_V1(trigger_test);
  
  Datum
  trigger_test(PG_FUNCTION_ARGS)
  {
    TriggerData *trigdata = (TriggerData *) fcinfo-&gt;context;
    TupleDesc   tupdesc;
    HeapTuple   rettuple;
  
    if (TRIGGER_FIRED_BY_UPDATE(trigdata-&gt;tg_event))
      rettuple = trigdata-&gt;tg_newtuple;
    else
      rettuple = trigdata-&gt;tg_trigtuple;
  
    tupdesc = trigdata-&gt;tg_relation-&gt;rd_att;
  
    bool isnull = false;
    int64 att = DatumGetInt64(heap_getattr(rettuple, 2, tupdesc, &amp;isnull));
  
    elog(INFO,"Value second column is: %d",att);
    return PointerGetDatum(rettuple);
  }
  </code></pre>
  
  <p>This file is in the same path of <strong>postgres.h</strong> and there are the files: <strong>executor/spi.h</strong> and <strong>commands/trigger.h</strong>. However, when I run the command:</p>
  
  <pre><code>cc -fpic -c trigger_test.c
  </code></pre>
  
  <p>I receive the errors:</p>
  
  <pre><code>In file included from postgres.h:48,
  from trigger_test.c:1:
     utils/elog.h:69:28: error: utils/errcodes.h: Not exists the file or directory
  In file included from trigger_test.c:2:
    executor/spi.h:16:30: error: nodes/parsenodes.h: Not exists the file or directory
    executor/spi.h:17:26: error: utils/portal.h: Not exists the file or directory
    executor/spi.h:18:28: error: utils/relcache.h: Not exists the file or directory
    executor/spi.h:19:28: error: utils/snapshot.h: Not exists the file or directory
  ...
  </code></pre>
  
  <p>All files exists and I don't want to change all includes in the files: <strong>elog.h</strong>, <strong>spi.h</strong>, etc, for the consequences that might have. Has anyone set up such triggers and can tell me where I'm wrong?</p>
  
  <p>Thanks in advance.</p>