| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk> | 
| Cc: | pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: C trigger problem | 
| Date: | 2005-09-17 14:08:40 | 
| Message-ID: | 7502.1126966120@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andreas Pflug | 2005-09-17 21:47:31 | Re: Beta2 Wrap Up ... | 
| Previous Message | Patrick Welche | 2005-09-17 13:41:45 | C trigger problem |