aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execMain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/execMain.c')
-rw-r--r--src/backend/executor/execMain.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 1cd4dbd2b90..a2271275571 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1855,7 +1855,6 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
ConstrCheck *check = rel->rd_att->constr->check;
ExprContext *econtext;
MemoryContext oldContext;
- int i;
/*
* CheckConstraintFetch let this pass with only a warning, but now we
@@ -1874,9 +1873,8 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_CheckConstraintExprs == NULL)
{
oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
- resultRelInfo->ri_CheckConstraintExprs =
- (ExprState **) palloc0(ncheck * sizeof(ExprState *));
- for (i = 0; i < ncheck; i++)
+ resultRelInfo->ri_CheckConstraintExprs = palloc0_array(ExprState *, ncheck);
+ for (int i = 0; i < ncheck; i++)
{
Expr *checkconstr;
@@ -1902,7 +1900,7 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
econtext->ecxt_scantuple = slot;
/* And evaluate the constraints */
- for (i = 0; i < ncheck; i++)
+ for (int i = 0; i < ncheck; i++)
{
ExprState *checkconstr = resultRelInfo->ri_CheckConstraintExprs[i];
@@ -2061,16 +2059,16 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
Assert(constr); /* we should not be called otherwise */
+ /*
+ * Verify not-null constraints.
+ */
if (constr->has_not_null)
{
- int natts = tupdesc->natts;
- int attrChk;
-
- for (attrChk = 1; attrChk <= natts; attrChk++)
+ for (AttrNumber attnum = 1; attnum <= tupdesc->natts; attnum++)
{
- Form_pg_attribute att = TupleDescAttr(tupdesc, attrChk - 1);
+ Form_pg_attribute att = TupleDescAttr(tupdesc, attnum - 1);
- if (att->attnotnull && slot_attisnull(slot, attrChk))
+ if (att->attnotnull && slot_attisnull(slot, attnum))
{
char *val_desc;
Relation orig_rel = rel;
@@ -2115,16 +2113,19 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
64);
ereport(ERROR,
- (errcode(ERRCODE_NOT_NULL_VIOLATION),
- errmsg("null value in column \"%s\" of relation \"%s\" violates not-null constraint",
- NameStr(att->attname),
- RelationGetRelationName(orig_rel)),
- val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
- errtablecol(orig_rel, attrChk)));
+ errcode(ERRCODE_NOT_NULL_VIOLATION),
+ errmsg("null value in column \"%s\" of relation \"%s\" violates not-null constraint",
+ NameStr(att->attname),
+ RelationGetRelationName(orig_rel)),
+ val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
+ errtablecol(orig_rel, attnum));
}
}
}
+ /*
+ * Verify check constraints.
+ */
if (rel->rd_rel->relchecks > 0)
{
const char *failed;