48 TriggerData *trigdata = (TriggerData *) fcinfo->context;
57 if (!CALLED_AS_TRIGGER(fcinfo))
58 elog(ERROR,
"cache_bbox: not called by trigger manager");
64 if ( trigdata->tg_trigger->tgnargs != 1 )
65 elog(ERROR,
"trigger 'cache_bbox' must be called with one argument");
67 trigger = trigdata->tg_trigger;
70 if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
71 rettuple = trigdata->tg_newtuple;
73 rettuple = trigdata->tg_trigtuple;
76 if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
78 elog(NOTICE,
"Useless cache_box trigger fired by DELETE");
79 return PointerGetDatum(rettuple);
81 if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
83 elog(NOTICE,
"Useless cache_box trigger fired AFTER");
84 return PointerGetDatum(rettuple);
86 if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
88 elog(NOTICE,
"Useless cache_box trigger fired for STATEMENT");
89 return PointerGetDatum(rettuple);
92 tupdesc = trigdata->tg_relation->rd_att;
95 if ((ret = SPI_connect()) < 0)
96 elog(ERROR,
"cache_bbox: SPI_connect returned %d", ret);
99 attno = SPI_fnumber(tupdesc, trigger->tgargs[0]);
100 if ( attno == SPI_ERROR_NOATTRIBUTE )
101 elog(ERROR,
"trigger %s can't find attribute %s",
102 trigger->tgname, trigger->tgargs[0]);
105 if ( strcmp(SPI_gettype(tupdesc, attno),
"geometry") )
106 elog(ERROR,
"trigger %s requested to apply to a non-geometry field (%s)", trigger->tgname, trigger->tgargs[0]);
109 in = SPI_getbinval(rettuple, tupdesc, attno, &isnull);
115 rettuple = SPI_modifytuple(trigdata->tg_relation, rettuple,
116 1, &attno, &out, NULL);
122 return PointerGetDatum(rettuple);
Datum LWGEOM_addBBOX(PG_FUNCTION_ARGS)