diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 7f2fd58..d636ed4 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -1300,11 +1300,10 @@ static List *
 get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec)
 {
 	List	   *result;
+	List	   *datums = NIL;
 	ArrayExpr  *arr;
 	Expr	   *opexpr;
-	ListCell   *cell,
-			   *prev,
-			   *next;
+	ListCell   *cell;
 	Expr	   *keyCol;
 	bool		list_has_null = false;
 	NullTest   *nulltest1 = NULL,
@@ -1322,24 +1321,17 @@ get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec)
 		keyCol = (Expr *) copyObject(linitial(key->partexprs));
 
 	/*
-	 * We must remove any NULL value in the list; we handle it separately
+	 * Create a list of datums without NULL; as we handle it separately
 	 * below.
 	 */
-	prev = NULL;
-	for (cell = list_head(spec->listdatums); cell; cell = next)
+	foreach (cell, spec->listdatums)
 	{
 		Const	   *val = (Const *) lfirst(cell);
 
-		next = lnext(cell);
-
 		if (val->constisnull)
-		{
 			list_has_null = true;
-			spec->listdatums = list_delete_cell(spec->listdatums,
-												cell, prev);
-		}
 		else
-			prev = cell;
+			datums = lappend(datums, lfirst(cell));
 	}
 
 	if (!list_has_null)
@@ -1373,7 +1365,7 @@ get_qual_for_list(PartitionKey key, PartitionBoundSpec *spec)
 		: key->parttypid[0];
 	arr->array_collid = key->parttypcoll[0];
 	arr->element_typeid = key->parttypid[0];
-	arr->elements = spec->listdatums;
+	arr->elements = datums;
 	arr->multidims = false;
 	arr->location = -1;
 
