MCPcopy Create free account
hub / github.com/apache/cloudberry / moddatetime

Function moddatetime

contrib/spi/moddatetime.c:29–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27PG_FUNCTION_INFO_V1(moddatetime);
28
29Datum
30moddatetime(PG_FUNCTION_ARGS)
31{
32 TriggerData *trigdata = (TriggerData *) fcinfo->context;
33 Trigger *trigger; /* to get trigger name */
34 int nargs; /* # of arguments */
35 int attnum; /* positional number of field to change */
36 Oid atttypid; /* type OID of field to change */
37 Datum newdt; /* The current datetime. */
38 bool newdtnull; /* null flag for it */
39 char **args; /* arguments */
40 char *relname; /* triggered relation name */
41 Relation rel; /* triggered relation */
42 HeapTuple rettuple = NULL;
43 TupleDesc tupdesc; /* tuple description */
44
45 if (!CALLED_AS_TRIGGER(fcinfo))
46 /* internal error */
47 elog(ERROR, "moddatetime: not fired by trigger manager");
48
49 if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
50 /* internal error */
51 elog(ERROR, "moddatetime: must be fired for row");
52
53 if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
54 /* internal error */
55 elog(ERROR, "moddatetime: must be fired before event");
56
57 if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
58 /* internal error */
59 elog(ERROR, "moddatetime: cannot process INSERT events");
60 else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
61 rettuple = trigdata->tg_newtuple;
62 else
63 /* internal error */
64 elog(ERROR, "moddatetime: cannot process DELETE events");
65
66 rel = trigdata->tg_relation;
67 relname = SPI_getrelname(rel);
68
69 trigger = trigdata->tg_trigger;
70
71 nargs = trigger->tgnargs;
72
73 if (nargs != 1)
74 /* internal error */
75 elog(ERROR, "moddatetime (%s): A single argument was expected", relname);
76
77 args = trigger->tgargs;
78 /* must be the field layout? */
79 tupdesc = rel->rd_att;
80
81 /*
82 * This gets the position in the tuple of the field we want. args[0] being
83 * the name of the field to update, as passed in from the trigger.
84 */
85 attnum = SPI_fnumber(tupdesc, args[0]);
86

Callers

nothing calls this directly

Calls 10

SPI_getrelnameFunction · 0.85
SPI_fnumberFunction · 0.85
SPI_gettypeidFunction · 0.85
CStringGetDatumFunction · 0.85
ObjectIdGetDatumFunction · 0.85
Int32GetDatumFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected