C trigger problem

Started by Patrick Welcheover 20 years ago2 messages
#1Patrick Welche
prlw1@newn.cam.ac.uk

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

I haven't seen anything similar in the documentation.. What is wrong / the
correct way of extracting values from the old/new rows in a C trigger fn?

Cheers,

Patrick

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Patrick Welche (#1)
Re: C trigger problem

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