From: | Louis-David Mitterrand <cunctator(at)apartia(dot)ch> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | modifying a timestamp in a C trigger |
Date: | 2000-08-14 14:47:33 |
Message-ID: | 20000814164733.A1765@styx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello,
I just finished a new C trigger that updated a "modified" column with
the current time upon an UPDATE event. It seems to work OK but I just
wanted to bounce this off you guys to check for some non-kosher stuff or
better way of doing it. Thanks in advance.
HeapTuple update_modified() {
TupleDesc tupdesc;
HeapTuple rettuple;
bool isnull;
TriggerData *trigdata = CurrentTriggerData;
/* Get the current datetime. */
Timestamp *tstamp = timestamp_in("now");
Datum newdt = Float32GetDatum(tstamp);
CurrentTriggerData = NULL;
if (!trigdata)
elog(NOTICE, "bid_control.c: triggers are not initialized");
if (!TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
elog(ERROR, "bid_control.c: trigger should only be called on INSERT");
if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
elog(ERROR, "bid_control.c: trigger should only be called BEFORE");
rettuple = trigdata->tg_trigtuple;
tupdesc = trigdata->tg_relation->rd_att;
if ((i = SPI_connect()) < 0)
elog(NOTICE, "bid_control.c: SPI_connect returned %d", i);
i = SPI_fnumber(tupdesc, "modified");
rettuple = SPI_modifytuple(
trigdata->tg_relation,
rettuple,
1,
&i,
&newdt,
NULL);
SPI_finish();
return rettuple;
}
--
Louis-David Mitterrand - ldm(at)apartia(dot)org - http://www.apartia.org
Lord, protect me from your followers.
From | Date | Subject | |
---|---|---|---|
Next Message | Don Baccus | 2000-08-14 17:45:19 | Re: modifying a timestamp in a C trigger |
Previous Message | Karel Zak | 2000-08-14 12:06:50 | Re: dangers of setlocale() in backend (was: problem with float8 input format) |