77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.122 2002/07/2005:16:57 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.123 2002/07/2019:55:38 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -50,6 +50,14 @@ static void DeferredTriggerExecute(DeferredTriggerEvent event, int itemno,
5050MemoryContext per_tuple_context );
5151
5252
53+ /*
54+ * Create a trigger. Returns the OID of the created trigger.
55+ *
56+ * forConstraint, if true, says that this trigger is being created to
57+ * implement a constraint. The caller will then be expected to make
58+ * a pg_depend entry linking the trigger to that constraint (and thereby
59+ * to the owning relation(s)).
60+ */
5361Oid
5462CreateTrigger (CreateTrigStmt * stmt ,bool forConstraint )
5563{
@@ -94,6 +102,12 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
94102if (aclresult != ACLCHECK_OK )
95103aclcheck_error (aclresult ,RelationGetRelationName (rel ));
96104
105+ /*
106+ * Generate the trigger's OID now, so that we can use it in the name
107+ * if needed.
108+ */
109+ trigoid = newoid ();
110+
97111/*
98112 * If trigger is an RI constraint, use specified trigger name as
99113 * constraint name and build a unique trigger name instead.
@@ -103,7 +117,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
103117if (stmt -> isconstraint )
104118{
105119snprintf (constrtrigname ,sizeof (constrtrigname ),
106- "RI_ConstraintTrigger_%u" ,newoid () );
120+ "RI_ConstraintTrigger_%u" ,trigoid );
107121trigname = constrtrigname ;
108122constrname = stmt -> trigname ;
109123}
@@ -279,10 +293,14 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
279293
280294tuple = heap_formtuple (tgrel -> rd_att ,values ,nulls );
281295
296+ /* force tuple to have the desired OID */
297+ AssertTupleDescHasOid (tgrel -> rd_att );
298+ HeapTupleSetOid (tuple ,trigoid );
299+
282300/*
283301 * Insert tuple into pg_trigger.
284302 */
285- trigoid = simple_heap_insert (tgrel ,tuple );
303+ simple_heap_insert (tgrel ,tuple );
286304
287305CatalogOpenIndices (Num_pg_trigger_indices ,Name_pg_trigger_indices ,idescs );
288306CatalogIndexInsert (idescs ,Num_pg_trigger_indices ,tgrel ,tuple );