diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-08-31 22:10:48 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-08-31 22:10:48 +0000 |
commit | 845a6c3acccea0ec34e70808787aa7d431b0d96d (patch) | |
tree | c6e162146378dc6cdb62793d3b30674b6d64d465 /src/backend/executor/execQual.c | |
parent | 1440acd703e04f39340f7fb3a432b028a791e038 (diff) | |
download | postgresql-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/executor/execQual.c')
-rw-r--r-- | src/backend/executor/execQual.c | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c index c53ac42b26f..30f5b0e378f 100644 --- a/src/backend/executor/execQual.c +++ b/src/backend/executor/execQual.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.105 2002/08/31 19:10:08 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.106 2002/08/31 22:10:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -69,8 +69,9 @@ static Datum ExecEvalNullTest(NullTest *ntest, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalBooleanTest(BooleanTest *btest, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); -static Datum ExecEvalConstraint(Constraint *constraint, ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone); +static Datum ExecEvalConstraintTest(ConstraintTest *constraint, + ExprContext *econtext, + bool *isNull, ExprDoneCond *isDone); /*---------- @@ -1465,43 +1466,6 @@ ExecEvalNullTest(NullTest *ntest, } } -/* - * ExecEvalConstraint - * - * Test the constraint against the data provided. If the data fits - * within the constraint specifications, pass it through (return the - * datum) otherwise throw an error. - */ -static Datum -ExecEvalConstraint(Constraint *constraint, ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone) -{ - Datum result; - - result = ExecEvalExpr(constraint->raw_expr, econtext, isNull, isDone); - - /* Test for the constraint type */ - switch(constraint->contype) - { - case CONSTR_NOTNULL: - if (*isNull) - { - elog(ERROR, "Domain %s does not allow NULL values", constraint->name); - } - break; - case CONSTR_CHECK: - - elog(ERROR, "ExecEvalConstraint: Domain CHECK Constraints not yet implemented"); - break; - default: - elog(ERROR, "ExecEvalConstraint: Constraint type unknown"); - break; - } - - /* If all has gone well (constraint did not fail) return the datum */ - return result; -} - /* ---------------------------------------------------------------- * ExecEvalBooleanTest * @@ -1582,6 +1546,41 @@ ExecEvalBooleanTest(BooleanTest *btest, } } +/* + * ExecEvalConstraintTest + * + * Test the constraint against the data provided. If the data fits + * within the constraint specifications, pass it through (return the + * datum) otherwise throw an error. + */ +static Datum +ExecEvalConstraintTest(ConstraintTest *constraint, ExprContext *econtext, + bool *isNull, ExprDoneCond *isDone) +{ + Datum result; + + result = ExecEvalExpr(constraint->arg, econtext, isNull, isDone); + + switch (constraint->testtype) + { + case CONSTR_TEST_NOTNULL: + if (*isNull) + elog(ERROR, "Domain %s does not allow NULL values", + constraint->name); + break; + case CONSTR_TEST_CHECK: + /* TODO: Add CHECK Constraints to domains */ + elog(ERROR, "Domain CHECK Constraints not yet implemented"); + break; + default: + elog(ERROR, "ExecEvalConstraintTest: Constraint type unknown"); + break; + } + + /* If all has gone well (constraint did not fail) return the datum */ + return result; +} + /* ---------------------------------------------------------------- * ExecEvalFieldSelect * @@ -1749,12 +1748,6 @@ ExecEvalExpr(Node *expression, isNull, isDone); break; - case T_Constraint: - retDatum = ExecEvalConstraint((Constraint *) expression, - econtext, - isNull, - isDone); - break; case T_CaseExpr: retDatum = ExecEvalCase((CaseExpr *) expression, econtext, @@ -1773,6 +1766,12 @@ ExecEvalExpr(Node *expression, isNull, isDone); break; + case T_ConstraintTest: + retDatum = ExecEvalConstraintTest((ConstraintTest *) expression, + econtext, + isNull, + isDone); + break; default: elog(ERROR, "ExecEvalExpr: unknown expression type %d", |