Good afternoon,
When I try to update part of a JSON Object, using ON DUPLICATE KEY UPDATE
, how do you update a specific value with a key?
The code executes successfully but all values are updated when I just want the stock to change on update.
Any help would be welcomed, I am not convinced, I understand the MySQL JSON Path syntax, or perhaps JSON_SET cannot achieve my goal?
INSERT INTO table (name, attributes) VALUES
("Sarah", JSON_OBJECT('profile', "F", "el", "[4, 5, 6]")),
("John", JSON_OBJECT('profile', "M", "el", "[10]"))
AS t
ON DUPLICATE KEY UPDATE
attributes = JSON_SET(t.attributes, '$.attributes.el', '$.attributes.el')
# ^
# +--- value being inserted
I have also tried another flavour without success:
attributes = JSON_REPLACE(t.attributes, '$.t.el', "$.t.el")
Third attempt using wildcards and json extract, which replaces the entire JSON_OBJECT()
attributes = JSON_REPLACE(t.attributes, '$.t[2]', JSON_EXTRACT(t.attributes, "$.stock"))