简体   繁体   English

MySQL正则表达式搜索JSON数组

[英]MySQL regexp search JSON array

I am storing json data to one of the fields in a table and I am having trouble using REGEXP to return the correct entry Basically, it matches other attributes in the JSON object, that it should not我将 json 数据存储到表中的一个字段,但在使用 REGEXP 返回正确条目时遇到问题 基本上,它与 JSON 对象中的其他属性匹配,它不应该

Sample JSON示例 JSON

    {
  "data": {
    "en": {
      "containers": [
        {
          "id": 1441530944931,
          "template": "12",
          "columns": {
            "column1": [
              "144",
              "145",
              "148"
            ],
            "column2":[
                "135",
                "148",
                "234"
            ]
          }
        }
      ],
      "left": "152",
      "right": "151"
    },

  }
}

Now, I would like to search the columns array against a specific value (ie 148)现在,我想针对特定值(即 148)搜索列数组

Right now I have the below query现在我有以下查询

WHERE (w.`_attrs` REGEXP '"column[0-9]":.*\\[.*"148".*\\]'

which works just fine However, if I change the value from 148 to 152 or 151, it also works For some reason the query matches the attribute left and right as well, but this is not desirable它工作得很好但是,如果我将值改为从148到152或者151,它也可以出于某种原因,查询匹配属性,为好,但这样做是不可取

Any help?有什么帮助吗?

Thanks谢谢

或者...切换到 MariaDB 10 并索引 JSON 的组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM