Patrick Welche <prlw1@newn.cam.ac.uk> writes:
> I am trying to write a C trigger. Essentially
> TriggerData *in = (TriggerData *) fcinfo->context;
> HeapTupleHeader tuple=in->tg_trigtuple->t_data;
> Datum datum;
> datum = GetAttributeByName(tuple, "unit_id", &isnull);
> and that last line fails with
> ERROR: cache lookup failed for type 4664
GetAttributeByName doesn't work on raw tuples-on-disk, because they
don't contain any type ID info. Use heap_getattr or one of the related
functions instead (perhaps in combination with SPI_fnumber if you don't
want a hardwired column number).
It strikes me that the current API for GetAttributeByName and
GetAttributeByNum is kinda broken, in that they cannot support this sort
of usage. The pre-8.0 API was little better, because back then they
wanted a TupleTableSlot which you don't have readily available either in
a trigger function. Thoughts anyone? Should we just deprecate these
functions and be done with it?
regards, tom lane