user2937998
user2937998

Reputation: 367

Search and replace JSON in Mysql with regex

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

Answers (1)

Rick James
Rick James

Reputation: 142356

MariaDB has REGEXP_REPLACE(), which might provide the tool you need.

Upvotes: 1

Related Questions