@@ -308,6 +308,12 @@ ExecInsert(ModifyTableState *mtstate,
308308 /* FDW might have changed tuple */
309309 tuple = ExecMaterializeSlot (slot );
310310
311+ /*
312+ * AFTER ROW Triggers or RETURNING expressions might reference the
313+ * tableoid column, so initialize t_tableOid before evaluating them.
314+ */
315+ tuple -> t_tableOid = RelationGetRelid (resultRelationDesc );
316+
311317 newId = InvalidOid ;
312318 }
313319 else
@@ -561,6 +567,8 @@ ExecDelete(ItemPointer tupleid,
561567 }
562568 else if (resultRelInfo -> ri_FdwRoutine )
563569 {
570+ HeapTuple tuple ;
571+
564572 /*
565573 * delete from foreign table: let the FDW do it
566574 *
@@ -579,6 +587,15 @@ ExecDelete(ItemPointer tupleid,
579587
580588 if (slot == NULL ) /* "do nothing" */
581589 return NULL ;
590+
591+ /*
592+ * RETURNING expressions might reference the tableoid column, so
593+ * initialize t_tableOid before evaluating them.
594+ */
595+ if (slot -> tts_isempty )
596+ ExecStoreAllNullTuple (slot );
597+ tuple = ExecMaterializeSlot (slot );
598+ tuple -> t_tableOid = RelationGetRelid (resultRelationDesc );
582599 }
583600 else
584601 {
@@ -838,6 +855,12 @@ ExecUpdate(ItemPointer tupleid,
838855
839856 /* FDW might have changed tuple */
840857 tuple = ExecMaterializeSlot (slot );
858+
859+ /*
860+ * AFTER ROW Triggers or RETURNING expressions might reference the
861+ * tableoid column, so initialize t_tableOid before evaluating them.
862+ */
863+ tuple -> t_tableOid = RelationGetRelid (resultRelationDesc );
841864 }
842865 else
843866 {
0 commit comments