mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Add pg_trigger_depth() function
This reports the depth level of triggers currently in execution, or zero if not called from inside a trigger. No catversion bump in this patch, but you have to initdb if you want access to the new function. Author: Kevin Grittner
This commit is contained in:
@ -59,6 +59,8 @@
|
||||
/* GUC variables */
|
||||
int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;
|
||||
|
||||
/* How many levels deep into trigger execution are we? */
|
||||
static int MyTriggerDepth = 0;
|
||||
|
||||
#define GetModifiedColumns(relinfo, estate) \
|
||||
(rt_fetch((relinfo)->ri_RangeTableIndex, (estate)->es_range_table)->modifiedCols)
|
||||
@ -1838,7 +1840,18 @@ ExecCallTriggerFunc(TriggerData *trigdata,
|
||||
|
||||
pgstat_init_function_usage(&fcinfo, &fcusage);
|
||||
|
||||
result = FunctionCallInvoke(&fcinfo);
|
||||
MyTriggerDepth++;
|
||||
PG_TRY();
|
||||
{
|
||||
result = FunctionCallInvoke(&fcinfo);
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
MyTriggerDepth--;
|
||||
PG_RE_THROW();
|
||||
}
|
||||
PG_END_TRY();
|
||||
MyTriggerDepth--;
|
||||
|
||||
pgstat_end_function_usage(&fcusage, true);
|
||||
|
||||
@ -4632,3 +4645,9 @@ AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
|
||||
&new_event, &new_shared);
|
||||
}
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_trigger_depth(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_RETURN_INT32(MyTriggerDepth);
|
||||
}
|
||||
|
Reference in New Issue
Block a user