summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2002-08-31 22:10:48 +0000
committerTom Lane2002-08-31 22:10:48 +0000
commit845a6c3acccea0ec34e70808787aa7d431b0d96d (patch)
treec6e162146378dc6cdb62793d3b30674b6d64d465 /src/include
parent1440acd703e04f39340f7fb3a432b028a791e038 (diff)
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/include')
-rw-r--r--src/include/nodes/nodes.h3
-rw-r--r--src/include/nodes/parsenodes.h28
-rw-r--r--src/include/parser/parse_coerce.h4
-rw-r--r--src/include/parser/parse_type.h3
-rw-r--r--src/include/utils/lsyscache.h4
5 files changed, 34 insertions, 8 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index 3f5f6d74499..ee472203e68 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: nodes.h,v 1.117 2002/08/27 04:55:11 tgl Exp $
+ * $Id: nodes.h,v 1.118 2002/08/31 22:10:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -229,6 +229,7 @@ typedef enum NodeTag
T_GroupClause,
T_NullTest,
T_BooleanTest,
+ T_ConstraintTest,
T_CaseExpr,
T_CaseWhen,
T_FkConstraint,
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 19d52d72175..a426aeba020 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.203 2002/08/30 19:23:20 tgl Exp $
+ * $Id: parsenodes.h,v 1.204 2002/08/31 22:10:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -233,14 +233,13 @@ typedef struct NullTest
NullTestType nulltesttype; /* IS NULL, IS NOT NULL */
} NullTest;
-/* ----------------
+/*
* BooleanTest
*
* BooleanTest represents the operation of determining whether a boolean
* is TRUE, FALSE, or UNKNOWN (ie, NULL). All six meaningful combinations
* are supported. Note that a NULL input does *not* cause a NULL result.
* The appropriate test is performed and returned as a boolean Datum.
- * ----------------
*/
typedef enum BoolTestType
@@ -256,6 +255,29 @@ typedef struct BooleanTest
} BooleanTest;
/*
+ * ConstraintTest
+ *
+ * ConstraintTest represents the operation of testing a value to see whether
+ * it meets a constraint. If so, the input value is returned as the result;
+ * if not, an error is raised.
+ */
+
+typedef enum ConstraintTestType
+{
+ CONSTR_TEST_NOTNULL,
+ CONSTR_TEST_CHECK
+} ConstraintTestType;
+
+typedef struct ConstraintTest
+{
+ NodeTag type;
+ Node *arg; /* input expression */
+ ConstraintTestType testtype; /* test type */
+ char *name; /* name of constraint (for error msgs) */
+ Node *check_expr; /* for CHECK test, a boolean expression */
+} ConstraintTest;
+
+/*
* ColumnDef - column definition (used in various creates)
*
* If the column has a default value, we may have the value expression
diff --git a/src/include/parser/parse_coerce.h b/src/include/parser/parse_coerce.h
index e306493fa36..328332aafd2 100644
--- a/src/include/parser/parse_coerce.h
+++ b/src/include/parser/parse_coerce.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parse_coerce.h,v 1.44 2002/06/20 20:29:51 momjian Exp $
+ * $Id: parse_coerce.h,v 1.45 2002/08/31 22:10:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -44,6 +44,8 @@ extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
Oid targetTypeId, int32 atttypmod, bool isExplicit);
extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
Oid targetTypeId, int32 atttypmod);
+extern Node *coerce_type_constraints(ParseState *pstate, Node *arg,
+ Oid typeId, bool applyTypmod);
extern Node *coerce_to_boolean(Node *node, const char *constructName);
diff --git a/src/include/parser/parse_type.h b/src/include/parser/parse_type.h
index f348a32d416..86c453882bc 100644
--- a/src/include/parser/parse_type.h
+++ b/src/include/parser/parse_type.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parse_type.h,v 1.23 2002/06/20 20:29:52 momjian Exp $
+ * $Id: parse_type.h,v 1.24 2002/08/31 22:10:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -31,6 +31,7 @@ extern Type typeidType(Oid id);
extern Oid typeTypeId(Type tp);
extern int16 typeLen(Type t);
extern bool typeByVal(Type t);
+extern char typeTypType(Type t);
extern char *typeTypeName(Type t);
extern char typeTypeFlag(Type t);
extern Oid typeTypeRelid(Type typ);
diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h
index 2681d67139f..3c442bbd202 100644
--- a/src/include/utils/lsyscache.h
+++ b/src/include/utils/lsyscache.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: lsyscache.h,v 1.60 2002/08/29 00:17:06 tgl Exp $
+ * $Id: lsyscache.h,v 1.61 2002/08/31 22:10:48 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -58,7 +58,7 @@ extern void getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem);
extern bool getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
bool *typIsVarlena);
extern Oid getBaseType(Oid typid);
-extern Oid getBaseTypeTypeMod(Oid typid, int32 *typmod);
+extern int32 getBaseTypeMod(Oid typid, int32 typmod);
extern int32 get_typavgwidth(Oid typid, int32 typmod);
extern int32 get_attavgwidth(Oid relid, AttrNumber attnum);
extern bool get_attstatsslot(HeapTuple statstuple,