@@ -1855,7 +1855,6 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
1855
1855
ConstrCheck * check = rel -> rd_att -> constr -> check ;
1856
1856
ExprContext * econtext ;
1857
1857
MemoryContext oldContext ;
1858
- int i ;
1859
1858
1860
1859
/*
1861
1860
* CheckConstraintFetch let this pass with only a warning, but now we
@@ -1874,9 +1873,8 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
1874
1873
if (resultRelInfo -> ri_CheckConstraintExprs == NULL )
1875
1874
{
1876
1875
oldContext = MemoryContextSwitchTo (estate -> es_query_cxt );
1877
- resultRelInfo -> ri_CheckConstraintExprs =
1878
- (ExprState * * ) palloc0 (ncheck * sizeof (ExprState * ));
1879
- for (i = 0 ; i < ncheck ; i ++ )
1876
+ resultRelInfo -> ri_CheckConstraintExprs = palloc0_array (ExprState * , ncheck );
1877
+ for (int i = 0 ; i < ncheck ; i ++ )
1880
1878
{
1881
1879
Expr * checkconstr ;
1882
1880
@@ -1902,7 +1900,7 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
1902
1900
econtext -> ecxt_scantuple = slot ;
1903
1901
1904
1902
/* And evaluate the constraints */
1905
- for (i = 0 ; i < ncheck ; i ++ )
1903
+ for (int i = 0 ; i < ncheck ; i ++ )
1906
1904
{
1907
1905
ExprState * checkconstr = resultRelInfo -> ri_CheckConstraintExprs [i ];
1908
1906
@@ -2061,16 +2059,16 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
2061
2059
2062
2060
Assert (constr ); /* we should not be called otherwise */
2063
2061
2062
+ /*
2063
+ * Verify not-null constraints.
2064
+ */
2064
2065
if (constr -> has_not_null )
2065
2066
{
2066
- int natts = tupdesc -> natts ;
2067
- int attrChk ;
2068
-
2069
- for (attrChk = 1 ; attrChk <= natts ; attrChk ++ )
2067
+ for (AttrNumber attnum = 1 ; attnum <= tupdesc -> natts ; attnum ++ )
2070
2068
{
2071
- Form_pg_attribute att = TupleDescAttr (tupdesc , attrChk - 1 );
2069
+ Form_pg_attribute att = TupleDescAttr (tupdesc , attnum - 1 );
2072
2070
2073
- if (att -> attnotnull && slot_attisnull (slot , attrChk ))
2071
+ if (att -> attnotnull && slot_attisnull (slot , attnum ))
2074
2072
{
2075
2073
char * val_desc ;
2076
2074
Relation orig_rel = rel ;
@@ -2115,16 +2113,19 @@ ExecConstraints(ResultRelInfo *resultRelInfo,
2115
2113
64 );
2116
2114
2117
2115
ereport (ERROR ,
2118
- ( errcode (ERRCODE_NOT_NULL_VIOLATION ),
2119
- errmsg ("null value in column \"%s\" of relation \"%s\" violates not-null constraint" ,
2120
- NameStr (att -> attname ),
2121
- RelationGetRelationName (orig_rel )),
2122
- val_desc ? errdetail ("Failing row contains %s." , val_desc ) : 0 ,
2123
- errtablecol (orig_rel , attrChk ) ));
2116
+ errcode (ERRCODE_NOT_NULL_VIOLATION ),
2117
+ errmsg ("null value in column \"%s\" of relation \"%s\" violates not-null constraint" ,
2118
+ NameStr (att -> attname ),
2119
+ RelationGetRelationName (orig_rel )),
2120
+ val_desc ? errdetail ("Failing row contains %s." , val_desc ) : 0 ,
2121
+ errtablecol (orig_rel , attnum ));
2124
2122
}
2125
2123
}
2126
2124
}
2127
2125
2126
+ /*
2127
+ * Verify check constraints.
2128
+ */
2128
2129
if (rel -> rd_rel -> relchecks > 0 )
2129
2130
{
2130
2131
const char * failed ;
0 commit comments