diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index bfabcdd0a4c..6e37fbbeae3 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -70,6 +70,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, @@ -2571,11 +2572,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 ffbdf2b4a00..952b862ccfc 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -3736,7 +3736,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 ddb5e6c0187..6c933b38951 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -309,6 +309,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