diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
index a8e530b177d..6d3208ade71 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
@@ -51,6 +51,9 @@ public function compile($conditionContainer) {
         $type = $this->nestedInsideOrCondition || strtoupper($this->conjunction) === 'OR' || $condition['operator'] === 'IS NULL' ? 'LEFT' : 'INNER';
         $field = $tables->addField($condition['field'], $type, $condition['langcode']);
         $condition['real_field'] = $field;
+        if (is_array($condition['value'])) {
+          $condition['value'] = array_values($condition['value']);
+        }
         static::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field']));
 
         // Add the translated conditions back to the condition container.
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
index f48ab65d878..33a9534c1f2 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
@@ -35,6 +35,9 @@ public function compile($conditionContainer) {
       else {
         $type = ((strtoupper($this->conjunction) == 'OR') || ($condition['operator'] == 'IS NULL')) ? 'LEFT' : 'INNER';
         $field = $tables->addField($condition['field'], $type, $condition['langcode']);
+        if (is_array($condition['value'])) {
+          $condition['value'] = array_values($condition['value']);
+        }
         $condition_class = QueryBase::getClass($this->namespaces, 'Condition');
         $condition_class::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field']));
         $function = $condition['function'];
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/pgsql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/pgsql/Condition.php
index f885a0e8234..cafa7af621e 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/pgsql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/pgsql/Condition.php
@@ -22,7 +22,7 @@ public static function translateCondition(&$condition, SelectInterface $sql_quer
       // argument following similar pattern in
       // \Drupal\Core\Database\Connection::expandArguments().
       $where_prefix = str_replace('.', '_', $condition['real_field']);
-      foreach ($condition['value'] as $key => $value) {
+      foreach (array_values($condition['value']) as $key => $value) {
         $where_id = $where_prefix . $key;
         $condition['where'] .= 'LOWER(:' . $where_id . '),';
         $condition['where_args'][':' . $where_id] = $value;
