Re: C trigger problem - Mailing list pgsql-hackers

From Tom Lane
Subject Re: C trigger problem
Date
Msg-id 7502.1126966120@sss.pgh.pa.us
Whole thread Raw
In response to C trigger problem  (Patrick Welche <prlw1@newn.cam.ac.uk>)
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Patrick Welche
Date:
Subject: C trigger problem
Next
From: Andreas Pflug
Date:
Subject: Re: Beta2 Wrap Up ...