aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-08-31 22:10:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-08-31 22:10:48 +0000
commit845a6c3acccea0ec34e70808787aa7d431b0d96d (patch)
treec6e162146378dc6cdb62793d3b30674b6d64d465 /src/backend/utils
parent1440acd703e04f39340f7fb3a432b028a791e038 (diff)
downloadpostgresql-845a6c3acccea0ec34e70808787aa7d431b0d96d.tar.gz
postgresql-845a6c3acccea0ec34e70808787aa7d431b0d96d.zip
Code review for domain-constraints patch. Use a new ConstraintTest node
type for runtime constraint checks, instead of misusing the parse-time Constraint node for the purpose. Fix some damage introduced into type coercion logic; in particular ensure that a coerced expression tree will read out the correct result type when inspected (patch had broken some RelabelType cases). Enforce domain NOT NULL constraints against columns that are omitted from an INSERT.
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/ruleutils.c14
-rw-r--r--src/backend/utils/cache/lsyscache.c26
2 files changed, 30 insertions, 10 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 458ab68749d..c7da14ad7ea 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.119 2002/08/29 01:19:41 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.120 2002/08/31 22:10:46 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -2187,6 +2187,18 @@ get_rule_expr(Node *node, deparse_context *context)
}
break;
+ case T_ConstraintTest:
+ {
+ ConstraintTest *ctest = (ConstraintTest *) node;
+
+ /*
+ * We assume that the operations of the constraint node
+ * need not be explicitly represented in the output.
+ */
+ get_rule_expr(ctest->arg, context);
+ }
+ break;
+
case T_SubLink:
get_sublink_expr(node, context);
break;
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index 66dc58d6c4b..4054b2920e6 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.81 2002/08/29 00:17:05 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.82 2002/08/31 22:10:47 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@@ -1074,12 +1074,12 @@ getBaseType(Oid typid)
}
/*
- * getBaseTypeTypeMod
- * If the given type is a domain, return its base type;
- * otherwise return the type's own OID. Also return base typmod.
+ * getBaseTypeMod
+ * If the given type is a domain, return the typmod it applies to
+ * its base type; otherwise return the specified original typmod.
*/
-Oid
-getBaseTypeTypeMod(Oid typid, int32 *typmod)
+int32
+getBaseTypeMod(Oid typid, int32 typmod)
{
/*
* We loop to find the bottom base type in a stack of domains.
@@ -1093,7 +1093,7 @@ getBaseTypeTypeMod(Oid typid, int32 *typmod)
ObjectIdGetDatum(typid),
0, 0, 0);
if (!HeapTupleIsValid(tup))
- elog(ERROR, "getBaseTypeTypeMod: failed to lookup type %u", typid);
+ elog(ERROR, "getBaseTypeMod: failed to lookup type %u", typid);
typTup = (Form_pg_type) GETSTRUCT(tup);
if (typTup->typtype != 'd')
{
@@ -1102,12 +1102,20 @@ getBaseTypeTypeMod(Oid typid, int32 *typmod)
break;
}
+ /*
+ * The typmod applied to a domain should always be -1.
+ *
+ * We substitute the domain's typmod as we switch attention to
+ * the base type.
+ */
+ Assert(typmod < 0);
+
typid = typTup->typbasetype;
- *typmod = typTup->typtypmod;
+ typmod = typTup->typtypmod;
ReleaseSysCache(tup);
}
- return typid;
+ return typmod;
}
/*