diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
index b3f6d64..2a92589 100644
--- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
@@ -138,6 +138,18 @@ class Connection extends DatabaseConnection {
     }
   }
 
+  public function prepareQuery($query) {
+    // In mapConditionOperator, LIKE operations are converted to ILIKE for
+    // consistency with mysql; however, Postgres does not support ILIKE on
+    // fields of type bytea (blobs). As a workaround, typecasting bytea fields
+    // to text fields allows the ILIKE operator to function correctly. We only
+    // need to add this typecast to fields that are of type bytea; however,
+    // there is no good place in the code where we can make this adjustment
+    // where the type of the field is known, so we settle on this compromise.
+    return parent::prepareQuery(preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE) /i', ' ${1}::text ${2} ', $query));
+  }
+
+
   public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
     return $this->query($query . ' LIMIT ' . (int) $count . ' OFFSET ' . (int) $from, $args, $options);
   }
