PostgreSQL Source Code git master
Loading...
Searching...
No Matches
trigfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "commands/trigger.h"
#include "utils/fmgrprotos.h"
Include dependency graph for trigfuncs.c:

Go to the source code of this file.

Functions

Datum suppress_redundant_updates_trigger (PG_FUNCTION_ARGS)
 

Function Documentation

◆ suppress_redundant_updates_trigger()

Datum suppress_redundant_updates_trigger ( PG_FUNCTION_ARGS  )

Definition at line 28 of file trigfuncs.c.

29{
30 TriggerData *trigdata = (TriggerData *) fcinfo->context;
31 HeapTuple newtuple,
32 oldtuple,
36
37 /* make sure it's called as a trigger */
38 if (!CALLED_AS_TRIGGER(fcinfo))
41 errmsg("suppress_redundant_updates_trigger: must be called as trigger")));
42
43 /* and that it's called on update */
44 if (!TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
47 errmsg("suppress_redundant_updates_trigger: must be called on update")));
48
49 /* and that it's called before update */
50 if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
53 errmsg("suppress_redundant_updates_trigger: must be called before update")));
54
55 /* and that it's called for each row */
56 if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
59 errmsg("suppress_redundant_updates_trigger: must be called for each row")));
60
61 /* get tuple data, set default result */
62 rettuple = newtuple = trigdata->tg_newtuple;
63 oldtuple = trigdata->tg_trigtuple;
64
65 newheader = newtuple->t_data;
66 oldheader = oldtuple->t_data;
67
68 /* if the tuple payload is the same ... */
69 if (newtuple->t_len == oldtuple->t_len &&
70 newheader->t_hoff == oldheader->t_hoff &&
73 ((newheader->t_infomask & ~HEAP_XACT_MASK) ==
74 (oldheader->t_infomask & ~HEAP_XACT_MASK)) &&
77 newtuple->t_len - SizeofHeapTupleHeader) == 0)
78 {
79 /* ... then suppress the update */
80 rettuple = NULL;
81 }
82
84}
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
#define HeapTupleHeaderGetNatts(tup)
#define SizeofHeapTupleHeader
#define HEAP_XACT_MASK
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static int fb(int x)
uint32 t_len
Definition htup.h:64
HeapTupleHeader t_data
Definition htup.h:68
#define TRIGGER_FIRED_BEFORE(event)
Definition trigger.h:130
#define CALLED_AS_TRIGGER(fcinfo)
Definition trigger.h:26
#define TRIGGER_FIRED_FOR_ROW(event)
Definition trigger.h:124
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition trigger.h:118

References CALLED_AS_TRIGGER, ereport, errcode(), errmsg(), ERROR, fb(), HEAP_XACT_MASK, HeapTupleHeaderGetNatts, PointerGetDatum(), SizeofHeapTupleHeader, HeapTupleData::t_data, HeapTupleData::t_len, TriggerData::tg_event, TriggerData::tg_newtuple, TriggerData::tg_trigtuple, TRIGGER_FIRED_BEFORE, TRIGGER_FIRED_BY_UPDATE, and TRIGGER_FIRED_FOR_ROW.