@@ -5392,6 +5392,28 @@ MakeTransitionCaptureState(TriggerDesc *trigdesc, Oid relid, CmdType cmdType)
53925392 if (need_new_ins && ins_table -> new_tuplestore == NULL )
53935393 ins_table -> new_tuplestore = tuplestore_begin_heap (false, false, work_mem );
53945394
5395+ /*
5396+ * BABELFISH: TSQL triggers are implicitly created with and old and new
5397+ * transition tables called "deleted" and "inserted" respectively. Since
5398+ * we've replaced the tcs_private field with individual ins, upd, del
5399+ * fields, with INSERTs we no longer create an empty tuplestore for old
5400+ * transition table and similarly for DELETEs we don't create a new one.
5401+ * However, since these transition tables are atleast accessible from a
5402+ * TSQL trigger, we should have an empty tuplestore for both of them
5403+ * anyway.
5404+ *
5405+ * Since these will be empty as per behaviour of INSERT and DELETE
5406+ * triggers, we are okay with simply creating an empty tuplestore for
5407+ * them.
5408+ */
5409+ if (sql_dialect == SQL_DIALECT_TSQL )
5410+ {
5411+ if (ins_table && ins_table -> old_tuplestore == NULL )
5412+ ins_table -> old_tuplestore = tuplestore_begin_heap (false, false, work_mem );
5413+ if (del_table && del_table -> new_tuplestore == NULL )
5414+ del_table -> new_tuplestore = tuplestore_begin_heap (false, false, work_mem );
5415+ }
5416+
53955417 CurrentResourceOwner = saveResourceOwner ;
53965418 MemoryContextSwitchTo (oldcxt );
53975419
0 commit comments