Reputation: 367
Is it possible to search and replace with a regex expression in MySQL?
I have a thousand values on a column containing a JSON string, somewhere inside each JSON are several occurrences of a string that I have to change.
I've already made a PHP script that do the job, but it is a little slow.
Is there a nicer way to do that using only MySQL?
Something like:
UPDATE mytable SET value = "disabled" WHERE data REGEXP '{"field": "(.+)"}'
Upvotes: 0
Views: 605
Reputation: 142356
MariaDB has REGEXP_REPLACE()
, which might provide the tool you need.
Upvotes: 1