Re: Better support for whole-row operations and composite

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Better support for whole-row operations and composite
Date: 2004-04-03 19:42:09
Message-ID: 406F1391.9090006@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> No, it's a HeapTupleHeader pointer. You need to reconstruct a
> HeapTuple on top of that to work with heap_getattr and most other
> core backend routines.

Thanks.

For triggers, I was previously building up the arguments thus:

slot = TupleDescGetSlot(tupdesc);
slot->val = trigdata->tg_trigtuple;
arg[7] = PointerGetDatum(slot);

I suppose now I should do this instead?

arg[7] = PointerGetDatum(trigdata->tg_trigtuple->t_data);

> Also don't forget to ensure that you detoast the datum; this is not
> useful at the moment but will be important Real Soon Now. I added
> standard argument-fetch macros to fmgr.h to help with the detoasting
> bit.

OK. This is the net result:

#ifdef PG_VERSION_75_COMPAT
Oid tupType;
int32 tupTypmod;
TupleDesc tupdesc;
HeapTuple tuple = palloc(sizeof(HeapTupleData));
HeapTupleHeader tuple_hdr = DatumGetHeapTupleHeader(arg[i]);

tupType = HeapTupleHeaderGetTypeId(tuple_hdr);
tupTypmod = HeapTupleHeaderGetTypMod(tuple_hdr);
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);

tuple->t_len = HeapTupleHeaderGetDatumLength(tuple_hdr);
ItemPointerSetInvalid(&(tuple->t_self));
tuple->t_tableOid = InvalidOid;
tuple->t_data = tuple_hdr;

PROTECT(el = pg_tuple_get_r_frame(1, &tuple, tupdesc));

pfree(tuple);
#else
TupleTableSlot *slot = (TupleTableSlot *) arg[i];
HeapTuple tuple = slot->val;
TupleDesc tupdesc = slot->ttc_tupleDescriptor;

PROTECT(el = pg_tuple_get_r_frame(1, &tuple, tupdesc));
#endif /* PG_VERSION_75_COMPAT */

Given the above changes, it's almost working now -- only problem left is
with triggers:

insert into foo values(11,'cat99',1.89);
+ ERROR: record type has not been registered
+ CONTEXT: In PL/R function rejectfoo

delete from foo;
+ ERROR: cache lookup failed for type 0
+ CONTEXT: In PL/R function rejectfoo

(and a few other similar failures)

Any ideas why the trigger tuple type isn't registered, or what I'm doing
wrong?

Thanks,

Joe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2004-04-03 20:03:14 Re: Inconsistent behavior on Array & Is Null?
Previous Message Greg Stark 2004-04-03 19:33:37 Re: Inconsistent behavior on Array & Is Null?