*** pgsql/src/backend/executor/execMain.c 2009/02/02 19:31:39 1.322 --- pgsql/src/backend/executor/execMain.c 2009/02/08 18:02:27 1.323 *************** *** 26,32 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.321 2009/01/22 20:16:03 tgl Exp $ * *------------------------------------------------------------------------- */ --- 26,32 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.322 2009/02/02 19:31:39 alvherre Exp $ * *------------------------------------------------------------------------- */ *************** ExecInsert(TupleTableSlot *slot, *** 1766,1771 **** --- 1766,1786 ---- resultRelInfo = estate->es_result_relation_info; resultRelationDesc = resultRelInfo->ri_RelationDesc; + /* + * If the result relation has OIDs, force the tuple's OID to zero so that + * heap_insert will assign a fresh OID. Usually the OID already will be + * zero at this point, but there are corner cases where the plan tree can + * return a tuple extracted literally from some table with the same + * rowtype. + * + * XXX if we ever wanted to allow users to assign their own OIDs to new + * rows, this'd be the place to do it. For the moment, we make a point + * of doing this before calling triggers, so that a user-supplied trigger + * could hack the OID if desired. + */ + if (resultRelationDesc->rd_rel->relhasoids) + HeapTupleSetOid(tuple, InvalidOid); + /* BEFORE ROW INSERT Triggers */ if (resultRelInfo->ri_TrigDesc && resultRelInfo->ri_TrigDesc->n_before_row[TRIGGER_EVENT_INSERT] > 0) *************** intorel_receive(TupleTableSlot *slot, De *** 3033,3038 **** --- 3048,3059 ---- */ tuple = ExecMaterializeSlot(slot); + /* + * force assignment of new OID (see comments in ExecInsert) + */ + if (myState->rel->rd_rel->relhasoids) + HeapTupleSetOid(tuple, InvalidOid); + heap_insert(myState->rel, tuple, myState->estate->es_output_cid,