aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/trigger.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-07-20 19:55:38 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-07-20 19:55:38 +0000
commitb70b78656b352cb4d00655b5ad653353e7d95e55 (patch)
tree900af738a30419e63d04d98c2adcf3bc22ae3d4b /src/backend/commands/trigger.c
parent17b28503d0d6c354606fce93d26b2febf18258c5 (diff)
downloadpostgresql-b70b78656b352cb4d00655b5ad653353e7d95e55.tar.gz
postgresql-b70b78656b352cb4d00655b5ad653353e7d95e55.zip
Tweak CreateTrigger() so that the OID used in the name of an
RI_ConstraintTrigger is the same OID assigned to the pg_trigger row. This reduces consumption of OIDs and may ease debugging.
Diffstat (limited to 'src/backend/commands/trigger.c')
-rw-r--r--src/backend/commands/trigger.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 4c2ee626fe0..353d684d903 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.122 2002/07/20 05:16:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.123 2002/07/20 19:55:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -50,6 +50,14 @@ static void DeferredTriggerExecute(DeferredTriggerEvent event, int itemno,
MemoryContext per_tuple_context);
+/*
+ * Create a trigger. Returns the OID of the created trigger.
+ *
+ * forConstraint, if true, says that this trigger is being created to
+ * implement a constraint. The caller will then be expected to make
+ * a pg_depend entry linking the trigger to that constraint (and thereby
+ * to the owning relation(s)).
+ */
Oid
CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
{
@@ -95,6 +103,12 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
aclcheck_error(aclresult, RelationGetRelationName(rel));
/*
+ * Generate the trigger's OID now, so that we can use it in the name
+ * if needed.
+ */
+ trigoid = newoid();
+
+ /*
* If trigger is an RI constraint, use specified trigger name as
* constraint name and build a unique trigger name instead.
* This is mainly for backwards compatibility with CREATE CONSTRAINT
@@ -103,7 +117,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
if (stmt->isconstraint)
{
snprintf(constrtrigname, sizeof(constrtrigname),
- "RI_ConstraintTrigger_%u", newoid());
+ "RI_ConstraintTrigger_%u", trigoid);
trigname = constrtrigname;
constrname = stmt->trigname;
}
@@ -279,10 +293,14 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
tuple = heap_formtuple(tgrel->rd_att, values, nulls);
+ /* force tuple to have the desired OID */
+ AssertTupleDescHasOid(tgrel->rd_att);
+ HeapTupleSetOid(tuple, trigoid);
+
/*
* Insert tuple into pg_trigger.
*/
- trigoid = simple_heap_insert(tgrel, tuple);
+ simple_heap_insert(tgrel, tuple);
CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);