如果我这样做:SELECT JSON_REMOVE(@I, '$.friends[*].name');
或 SELECT JSON_REMOVE(@I, '$.friends[*]. friends');
在下面的 JSON 中,我得到了这个错误:
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
。
最佳答案
json_remove
、json_set
等函数好像MySQL不支持通配符
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
关于mysql - array.array 的 JSON_REMOVE 导致 "path expressions may not contain the * and ** tokens"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38890938/