diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 8cc6591978d..f60d29d54df 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -72,6 +72,7 @@ int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN; /* How many levels deep into trigger execution are we? */ static int MyTriggerDepth = 0; +List *triggerOids = NIL; /* To store all trigger calls information */ /* Local function prototypes */ static void renametrig_internal(Relation tgrel, Relation targetrel, @@ -2508,11 +2509,13 @@ ExecCallTriggerFunc(TriggerData *trigdata, MyTriggerDepth++; PG_TRY(); { + triggerOids = lappend_oid(triggerOids, trigdata->tg_trigger->tgoid); result = FunctionCallInvoke(fcinfo); } PG_FINALLY(); { MyTriggerDepth--; + triggerOids = list_delete_oid(triggerOids, trigdata->tg_trigger->tgoid); } PG_END_TRY(); diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index 34a27aa8be4..4fdd63ad6fb 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -3728,7 +3728,8 @@ RewriteQuery(Query *parsetree, List *rewrite_events, int orig_rt_length) result_relation = parsetree->resultRelation; Assert(result_relation != 0); rt_entry = rt_fetch(result_relation, parsetree->rtable); - Assert(rt_entry->rtekind == RTE_RELATION); + /** allow transition table in TSQL inside trigger body, rtekind can be RTE_NAMEDTUPLESTORE, eg inserted and deleted*/ + Assert(rt_entry->rtekind == RTE_RELATION || (sql_dialect == SQL_DIALECT_TSQL && rt_entry->rtekind == RTE_NAMEDTUPLESTORE)); /* * We can use NoLock here since either the parser or diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index 59ad3e437da..ea7b410f4ee 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -291,6 +291,7 @@ extern void AfterTriggerEndSubXact(bool isCommit); extern void AfterTriggerSetState(ConstraintsSetStmt *stmt); extern bool AfterTriggerPendingOnRel(Oid relid); +extern List *triggerOids; /* To store all trigger calls information */ /* * in utils/adt/ri_triggers.c