Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > Re: minimal upd...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 9324 of 10118
Post > Topic >>

Re: minimal update

by andrew@[EMAIL PROTECTED] (Andrew Dunstan) May 7, 2008 at 09:36 PM

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, 
>> do***ented, 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);
}|




-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
 




 6 Posts in Topic:
Re: minimal update
bruce@[EMAIL PROTECTED]   2008-05-07 20:34:20 
Re: minimal update
andrew@[EMAIL PROTECTED]   2008-05-07 20:38:02 
Re: minimal update
bruce@[EMAIL PROTECTED]   2008-05-07 21:16:56 
Re: minimal update
andrew@[EMAIL PROTECTED]   2008-05-07 21:25:01 
Re: minimal update
bruce@[EMAIL PROTECTED]   2008-05-07 21:29:22 
Re: minimal update
andrew@[EMAIL PROTECTED]   2008-05-07 21:36:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 7:01:20 CDT 2008.