0

This MySQL statement runs fine on MySQL 8.0.33-0ubuntu0.20.04.2:

mysql> UPDATE node__body SET body_value = REGEXP_REPLACE(body_value, "<img.*base64.*>", "");
Query OK, 0 rows affected (1.58 sec)
Rows matched: 14136  Changed: 0  Warnings: 0

However, when I run the command in an update hook like this:

$database = \Drupal::database();
$database->query('UPDATE node__body SET body_value = REGEXP_REPLACE(body_value, "<img.*base64.*>", "")');

There is an error complaining about unknown column.

>  [error]  SQLSTATE[42S22]: Column not found: 1054 Unknown column '<img .*base64.*>' in 'field list': UPDATE node__body SET body_value = REGEXP_REPLACE(body_value, "<img .*base64.*>", ""); Array
0

1 Answer 1

0

Was able to get REGEXP_REPLACE to work with the following way:

$database->update('node__body')
  ->expression('body_value', "REGEXP_REPLACE(body_value, '<img.*base64.*>', '')")
  ->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.