Thus spake Tom Lane
> darcy@druid.net (D'Arcy J.M. Cain) writes:
> >> heap_formtuple is for constructing a tuple from scratch. It sounds like
> >> you should be using heap_modifytuple instead.
>
> > But I am using SPI_modifytuple(). The rest came from tracing that
> > function.
>
> Hm. Looks like the author of SPI_modifytuple didn't realize he could
> use heap_modifytuple :-(. But he is correctly extracting the old data.
> I don't see anything wrong there, assuming that you are passing a
> relation descriptor that matches the original tuple.
Well, let's see.
SPI_modifytuple (rel,rettuple,1,&targ_att,&newval,NULL)
Here are (I think) the relevant lines that get me the data for that call.
Datum
mk_cardnum(PG_FUNCTION_ARGS)
{ TriggerData *trigdata = (TriggerData *) fcinfo->context; int nargs; /* # of arguments */ Datum
newval; /* new value of column */ char **args; /* arguments */ char *relname;
/* triggered relation name */ Relation rel; /* triggered relation */ HeapTuple rettuple = NULL;
int targ_att; bool isnull; char cardnum[48];
... /* assume full error checking - leaving out for clarity */ rel = trigdata->tg_relation; relname =
SPI_getrelname(rel); targ_att = SPI_fnumber (tupdesc, args[0]); newval = CStringGetDatum(cardnum);
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.