如果我在下面的JSON上执行:SELECT JSON_REMOVE(@I, '$.friends[*].name');
或SELECT JSON_REMOVE(@I, '$.friends[*].friends');
,我会收到此错误:
ERROR 3149 (42000): In this situation, path expressions may not contain the * and ** tokens.
JSON:
SET @I = '{
"name": "Alice",
"friends": [
{
"name": "Bob",
"friends": [
{
"name": "Carl",
"friends": []
},
{
"name": "Danny",
"friends": []
}
]
},
{
"name": "Edward",
"friends": [
{
"name": "Frank",
"friends": []
},
{
"name": "Gary",
"friends": []
}
]
}
]
}';
然而 如果我SELECT JSON_EXTRACT(@I, '$.friends[*].friends')
,则会返回结果。
[[{"friends": [], "name": "Carl"}, {"friends": [], "name": "Danny"}], [{"name": "Frank", "friends": []}, {"name": "Gary", "friends": []}]]
基本上我想要返回一个字符串,其中删除了所有friends.name
,甚至可能删除了friends.friends
。
答案 0 :(得分:0)
看起来MySQL不支持json_remove
,json_set
等功能的通配符。
bool Item_func_json_remove::val_json(Json_wrapper *wr)
{
//bla-bla-bla
if (m_path_cache.parse_and_cache_path(args, path_idx + 1, true))
}
和
bool Json_path_cache::parse_and_cache_path(Item ** args, uint arg_idx,
bool forbid_wildcards)
https://github.com/mysql/mysql-server/blob/5.7/sql/item_json_func.cc#L3227 https://github.com/mysql/mysql-server/blob/5.7/sql/item_json_func.cc#L2563 https://github.com/mysql/mysql-server/blob/5.7/sql/item_json_func.cc#L534