array.array的JSON_REMOVE导致“路径表达式可能不包含*和**标记”错误

时间:2016-08-11 08:20:03

标签: mysql json mysql-5.7 mysql-json

如果我在下面的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

1 个答案:

答案 0 :(得分:0)

看起来MySQL不支持json_removejson_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