I have MySQL 5.7.12 DB with a table that has a JSON column.
The data in the column as the following structure (json array may contain more than 2 json-objects:
[{"ste": "I", "tpe": "PS"}, {"ste": "I", "tpe": "PB"}]
I would like to craft an UPDATE
query that changes the value of ste
where tpe=PB
.
Here is my attempt:
UPDATE user SET ext = JSON_SET(JSON_SEARCH(ext, 'one', 'PB', NULL, '$**.tpe'), '$.tpe', 'A');
The output if the query should give:
[{"ste": "I", "tpe": "PS"}, {"ste": "A", "tpe": "PB"}]
It doesn't work - it updates the column to be:
"$[0].tpe"
How can I make this work?
EDIT
I think this makes more sense but still something wrong with syntax
UPDATE user SET ext = JSON_SET(ext->JSON_SEARCH(ext, 'one', 'PS', NULL, '$**.tpe'), '$.tpe', 'A');