aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/trigger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/trigger.c')
-rw-r--r--src/backend/commands/trigger.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index f5e12e5681d..2838b66e402 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -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);
+}