Re: minimal update

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, David Fetter <david(at)fetter(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: minimal update
Date: 2008-10-16 02:42:11
Message-ID: 200810160242.m9G2gBF06628@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan wrote:
>
> Bruce,
>
> did you ever look at completing this?

No, it is still in my email box unaddressed. Feel free to work on it; I
doubt I can do it for 8.4.

---------------------------------------------------------------------------

>
> cheers
>
> andrew
>
> Andrew Dunstan wrote:
> >
> >
> > Bruce Momjian wrote:
> >> Andrew Dunstan wrote:
> >>
> >>> Right. In fact, I already had that part in fact - see
> >>> http://people.planetpostgresql.org/andrew/index.php?/archives/22-Minimal-Update-Trigger.html
> >>>
> >>>
> >>> What I was waiting for was the part where it gets put in the
> >>> catalog, documented, etc.
> >>>
> >>
> >> I can probably do that part. Send over what you have and I will work on
> >> it. Thanks.
> >>
> >>
> >
> > It's very similar to what Gurjeet posted (but designed to work with
> > earlier postgres versions)
> >
> > cheers
> >
> > andrew
> >
> > ---
> >
> > |#include "postgres.h"
> > #include "commands/trigger.h"
> > #include "access/htup.h"
> >
> > #ifdef PG_MODULE_MAGIC
> > PG_MODULE_MAGIC;
> > #endif
> >
> > /* for pre 8.3 */
> > #ifndef HeapTupleHeaderGetNatts
> > #define HeapTupleHeaderGetNatts(th) ( (th)->t_natts )
> > #endif
> >
> > extern Datum min_update_trigger(PG_FUNCTION_ARGS);
> >
> > PG_FUNCTION_INFO_V1(min_update_trigger);
> >
> > Datum
> > min_update_trigger(PG_FUNCTION_ARGS)
> > {
> > TriggerData *trigdata = (TriggerData *) fcinfo->context;
> > HeapTuple newtuple, oldtuple, rettuple;
> >
> > /* make sure it's called as a trigger at all */
> > if (!CALLED_AS_TRIGGER(fcinfo))
> > elog(ERROR, "min_update_trigger: not called by trigger manager");
> >
> > /* and that it's called on update */
> > if (! TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
> > elog(ERROR, "min_update_trigger: not called on update");
> >
> > /* and that it's called before update */
> > if (! TRIGGER_FIRED_BEFORE(trigdata->tg_event))
> > elog(ERROR, "min_update_trigger: not called before update");
> >
> > /* and that it's called for each row */
> > if (! TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
> > elog(ERROR, "min_update_trigger: not called for each row");
> >
> > /* get tuple dat, set default return */
> > rettuple = newtuple = trigdata->tg_newtuple;
> > oldtuple = trigdata->tg_trigtuple;
> >
> > if (newtuple->t_len == oldtuple->t_len &&
> > newtuple->t_data->t_hoff == oldtuple->t_data->t_hoff &&
> > HeapTupleHeaderGetNatts(newtuple->t_data) ==
> > HeapTupleHeaderGetNatts(oldtuple->t_data) &&
> > (newtuple->t_data->t_infomask & ~HEAP_XACT_MASK) ==
> > (oldtuple->t_data->t_infomask & ~HEAP_XACT_MASK) &&
> > memcmp(((char *)newtuple->t_data) +
> > offsetof(HeapTupleHeaderData, t_bits),
> > ((char *)oldtuple->t_data) +
> > offsetof(HeapTupleHeaderData, t_bits),
> > newtuple->t_len -
> > offsetof(HeapTupleHeaderData, t_bits)) == 0)
> > rettuple = NULL;
> >
> > return PointerGetDatum(rettuple);
> > }|
> >
> >
> >
> >

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-10-16 02:58:21 Re: autovacuum and reloptions
Previous Message Robert Haas 2008-10-16 02:33:31 Re: array_agg (was Re: The Axe list)