2

如果我这样做: 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删除的字符串。

4

1 回答 1

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

于 2017-09-13T07:09:53.723 回答