diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 81b9d87bad..e9b9239283 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -3129,6 +3129,8 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
 {
 	DomainConstraintRef *constraint_ref;
 	ListCell   *l;
+	Datum	   *domainval = NULL;
+	bool	   *domainnull = NULL;
 
 	scratch->d.domaincheck.resulttype = ctest->resulttype;
 	/* we'll allocate workspace only if needed */
@@ -3174,10 +3176,6 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
 	foreach(l, constraint_ref->constraints)
 	{
 		DomainConstraintState *con = (DomainConstraintState *) lfirst(l);
-		Datum	   *domainval = NULL;
-		bool	   *domainnull = NULL;
-		Datum	   *save_innermost_domainval;
-		bool	   *save_innermost_domainnull;
 
 		scratch->d.domaincheck.constraintname = con->name;
 
@@ -3188,6 +3186,10 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
 				ExprEvalPushStep(state, scratch);
 				break;
 			case DOM_CONSTRAINT_CHECK:
+			{
+				Datum	   *save_innermost_domainval;
+				bool	   *save_innermost_domainnull;
+
 				/* Allocate workspace for CHECK output if we didn't yet */
 				if (scratch->d.domaincheck.checkvalue == NULL)
 				{
@@ -3255,6 +3257,7 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
 				ExprEvalPushStep(state, scratch);
 
 				break;
+			}
 			default:
 				elog(ERROR, "unrecognized constraint type: %d",
 					 (int) con->constrainttype);