0
創建觸發器我在Ubuntu 10.04一個PostgreSQL 9.0服務器,我嘗試創建C代碼的觸發,之後的下一個環節:在C對PostgreSQL的9
對於目前,我的代碼應該顯示在記錄列的唯一值(並返回「編輯」記錄):
#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->context;
TupleDesc tupdesc;
HeapTuple rettuple;
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
rettuple = trigdata->tg_newtuple;
else
rettuple = trigdata->tg_trigtuple;
tupdesc = trigdata->tg_relation->rd_att;
bool isnull = false;
int64 att = DatumGetInt64(heap_getattr(rettuple, 2, tupdesc, &isnull));
elog(INFO,"Value second column is: %d",att);
return PointerGetDatum(rettuple);
}
此文件是了postgres.h相同的路徑,並有日e文件:executor/spi.h和commands/trigger.h。然而,當我運行命令:
cc -fpic -c trigger_test.c
我收到錯誤:
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
...
所有文件存在,我不想改變所有包含的文件:elog.h, spi.h等,可能產生的後果。有沒有人設置這樣的觸發器,並可以告訴我我錯在哪裏?
在此先感謝。
嘗試增加'-I.'命令行:'CC -fpic -c -I。 trigger_test.c'。 – 2012-01-30 13:05:09
非常感謝,至少現在編譯完成。 – doctore 2012-01-30 13:41:46