aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-01-17 22:56:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-01-17 22:56:23 +0000
commit9a915e596f38a97f10e00d388f18e178136937eb (patch)
treec0f85775a2423e0fb28c4d96d85569781668011e /src/backend/utils/adt/ruleutils.c
parentee3b4188a78916544ef30e93fc1c9e5e780e07d5 (diff)
downloadpostgresql-9a915e596f38a97f10e00d388f18e178136937eb.tar.gz
postgresql-9a915e596f38a97f10e00d388f18e178136937eb.zip
Improve the handling of SET CONSTRAINTS commands by having them search
pg_constraint before searching pg_trigger. This allows saner handling of corner cases; in particular we now say "constraint is not deferrable" rather than "constraint does not exist" when the command is applied to a constraint that's inherently non-deferrable. Per a gripe several months ago from hubert depesz lubaczewski. To make this work without breaking user-defined constraint triggers, we have to add entries for them to pg_constraint. However, in return we can remove the pgconstrname column from pg_constraint, which represents a fairly sizable space savings. I also replaced the tgisconstraint column with tgisinternal; the old meaning of tgisconstraint can now be had by testing for nonzero tgconstraint, while there is no other way to get the old meaning of nonzero tgconstraint, namely that the trigger was internally generated rather than being user-created. In passing, fix an old misstatement in the docs and comments, namely that pg_trigger.tgdeferrable is exactly redundant with pg_constraint.condeferrable. Actually, we mark RI action triggers as nondeferrable even when they belong to a nominally deferrable FK constraint. The SET CONSTRAINTS code now relies on that instead of hard-coding a list of exception OIDs.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index d9cc1258f0a..2eeb0bc5152 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.318 2010/01/02 16:57:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.319 2010/01/17 22:56:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -519,7 +519,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
tgname = NameStr(trigrec->tgname);
appendStringInfo(&buf, "CREATE %sTRIGGER %s",
- trigrec->tgisconstraint ? "CONSTRAINT " : "",
+ OidIsValid(trigrec->tgconstraint) ? "CONSTRAINT " : "",
quote_identifier(tgname));
appendStringInfoString(&buf, pretty ? "\n " : " ");
@@ -577,7 +577,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
generate_relation_name(trigrec->tgrelid, NIL));
appendStringInfoString(&buf, pretty ? "\n " : " ");
- if (trigrec->tgisconstraint)
+ if (OidIsValid(trigrec->tgconstraint))
{
if (OidIsValid(trigrec->tgconstrrelid))
{
@@ -1276,6 +1276,15 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
break;
}
+ case CONSTRAINT_TRIGGER:
+ /*
+ * There isn't an ALTER TABLE syntax for creating a user-defined
+ * constraint trigger, but it seems better to print something
+ * than throw an error; if we throw error then this function
+ * couldn't safely be applied to all rows of pg_constraint.
+ */
+ appendStringInfo(&buf, "TRIGGER");
+ break;
case CONSTRAINT_EXCLUSION:
{
Oid indexOid = conForm->conindid;