我想在MySQL中更新一个JSON对象。
表
id (int-11, not_null, auto_inc)
labels (json)JSON美化
[
{
"tagname": "FOO",
"category": "CAT_1",
"isnew": "no",
"isdeleted": "no"
},
{
"tagname": "BAR",
"category": "CAT_2",
"isnew": "yes",
"isdeleted": "no"
}
]--我想在现有对象的旁边添加一个新的标记元素(JSON对象),但是没有SELECTing,首先是字段,然后用文本更新所有字段。我有很多Google,但是我还不能理解MySQL的JSON处理。我刚刚学会了如何插入这样的数据:
INSERT INTO `table_name`(
`id` ,
`labels`
)
VALUES(
null ,
JSON_ARRAY
(
JSON_OBJECT
(
"tagname", "FOO",
"category", "CAT_1",
"isnew", "no",
"isdeleted", "no"
),
JSON_OBJECT
(
"tagname", "BAR",
"category", "CAT_2",
"isnew", "yes",
"isdeleted", "no"
)
)
);发布于 2018-08-14 15:46:39
你可以用附文
UPDATE tab
SET labels = JSON_ARRAY_APPEND(labels, '$',
JSON_OBJECT
(
"tagname", "BARX",
"category", "CAT_3",
"isnew", "yes",
"isdeleted", "no"
)
)
WHERE ID = 1;https://stackoverflow.com/questions/51845151
复制相似问题