On Wed, 9 Feb 2000, Thomas Egge wrote:
> I have created a trigger function.
>
> could somebody tell me how I get the values from the insert in the trigger
> function.
> I tried the function
>
> SPI_getvalue(trigger,tupdesc,attnum)
>
Example:
TupleDesc tupdesc;
HeapTuple rettuple = NULL;
char *value;
if (!CurrentTriggerData)
elog(ERROR, "triggers are not initialized");
if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
rettuple = CurrentTriggerData->tg_newtuple;
else if (TRIGGER_FIRED_BY_INSERT(CurrentTriggerData->tg_event))
rettuple = CurrentTriggerData->tg_trigtuple;
else if (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event))
rettuple = CurrentTriggerData->tg_trigtuple;
tupdesc = CurrentTriggerData->tg_relation->rd_att;
if (SPI_connect() < 0)
elog(ERROR, "SPI_connect()");
value = SPI_getvalue(rettuple, tupdesc, SPI_fnumber(tupdesc, "column_name"));
...see the PostgreSQL programmer's guide for more...
Karel