diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index a6db219..c0dea29 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -211,7 +211,16 @@ public function prepareQuery($query) { // @todo This workaround only affects bytea fields, but the involved field // types involved in the query are unknown, so there is no way to // conditionally execute this for affected queries only. - return parent::prepareQuery(preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE|~\*|~) /i', ' ${1}::text ${2} ', $query)); + $query = preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE) /i', ' ${1}::text ${2} ', $query); + + // SIMILAR TO works only for text, so make sure we cast the type. + $query = preg_replace('/ ([^ ]+) +(SIMILAR TO|NOT SIMILAR TO) /i', ' ${1}::text ${2} ', $query); + + // Regular expression match operators '~', '~*', '!~', '!~*' works only for + // text, so make sure we cast the type. + $query = preg_replace('/ ([^ ]+) +(~|~\*|!~|!~\*) /i', ' ${1}::text ${2} ', $query); + + return parent::prepareQuery($query); } public function queryRange($query, $from, $count, array $args = array(), array $options = array()) { diff --git a/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php b/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php index 678375a..ca15879 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php @@ -219,7 +219,7 @@ public function testFilterNumericRegularExpression() { $view = Views::getView('test_view'); $view->setDisplay(); - // Filtering by regular expression syntax + // Filtering by regular expression pattern. $view->displayHandlers->get('default')->overrideOption('filters', array( 'age' => array( 'id' => 'age',