mysql - array.array 的 JSON_REMOVE 导致 "path expressions may not contain the * and ** tokens"错误

标签 mysql json mysql-5.7 mysql-json

如果我这样做: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_removejson_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/

相关文章:

mysql - 由于重复条目错误,更改 MySQL (Percona 5.7) 表失败

MySQL 5.7 | MySQL 5.7分组依据 |独特|聚合错误

php - 我是在从 sql 注入(inject)中拯救自己吗?

json - Wordpress REST API _fields 和 _embed 参数不能同时工作

json - 如何动态添加结构属性以避免冗余代码?

javascript - 创建更好的 JSON 格式

mysql - 使用 Yum 安装 MYSQL 5.7 时出错

c# - 登录不区分大小写

mysql - 只有 else 条件是在插入或更新期间使用存储过程在 mysql 中执行

PHP过滤mysql结果