我在mysql表中有一个带有以下示例数据的json字段名称shipping_info
{
"shipping": {
"0": {
"phone": "(222) 222-2222",
"address1": "streeta",
"address2": null,
"address3": null,
"attention": "company",
"phone_ext": null,
"postal_code": "91406",
"proper_city": "VAN NUYS",
"address_type": "u",
"city_or_town": "VAN NUYS",
"country_code": "US"
}
}
}
我的目标是更新此路径shipping.0.address1
中的值。
到目前为止,这是我的查询,但似乎无效
UPDATE cart_items
SET shipping_info = JSON_SET(
shipping_info,
'$.shipping[0].address1', 'new value'
)
WHERE cart_item_id= 1;
答案 0 :(得分:0)
我能够通过以下查询进行操作:
UPDATE cart_items
SET shipping_info = JSON_SET(
shipping_info,
'$.shipping."0".address1', 'new value'
)
WHERE cart_item_id= 1;
我将其发布为答案,以防万一有人也会遇到相同的情况。