7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.122 2002/07/20 05:16:57 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.123 2002/07/20 19:55:38 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -50,6 +50,14 @@ static void DeferredTriggerExecute(DeferredTriggerEvent event, int itemno,
50
50
MemoryContext per_tuple_context );
51
51
52
52
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
+ */
53
61
Oid
54
62
CreateTrigger (CreateTrigStmt * stmt , bool forConstraint )
55
63
{
@@ -94,6 +102,12 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
94
102
if (aclresult != ACLCHECK_OK )
95
103
aclcheck_error (aclresult , RelationGetRelationName (rel ));
96
104
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
+
97
111
/*
98
112
* If trigger is an RI constraint, use specified trigger name as
99
113
* constraint name and build a unique trigger name instead.
@@ -103,7 +117,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
103
117
if (stmt -> isconstraint )
104
118
{
105
119
snprintf (constrtrigname , sizeof (constrtrigname ),
106
- "RI_ConstraintTrigger_%u" , newoid () );
120
+ "RI_ConstraintTrigger_%u" , trigoid );
107
121
trigname = constrtrigname ;
108
122
constrname = stmt -> trigname ;
109
123
}
@@ -279,10 +293,14 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
279
293
280
294
tuple = heap_formtuple (tgrel -> rd_att , values , nulls );
281
295
296
+ /* force tuple to have the desired OID */
297
+ AssertTupleDescHasOid (tgrel -> rd_att );
298
+ HeapTupleSetOid (tuple , trigoid );
299
+
282
300
/*
283
301
* Insert tuple into pg_trigger.
284
302
*/
285
- trigoid = simple_heap_insert (tgrel , tuple );
303
+ simple_heap_insert (tgrel , tuple );
286
304
287
305
CatalogOpenIndices (Num_pg_trigger_indices , Name_pg_trigger_indices , idescs );
288
306
CatalogIndexInsert (idescs , Num_pg_trigger_indices , tgrel , tuple );
0 commit comments