【问题标题】:How do I use JSON_SEARCH() to find the path of a number in a MySQL JSON array?如何使用 JSON_SEARCH() 在 MySQL JSON 数组中查找数字的路径?
【发布时间】:2017-10-18 19:29:56
【问题描述】:

注意:这是针对 MySQL 5.7 的。

当我尝试使用 JSON_SEARCH 在 JSON 数组中查找数字值的路径时,我得到了 NULL。但是当我使用JSON_SEARCH 查找字符串时,我实际上得到了路径。

# String Search Example

SET @json = '[1, 2, 3, "abc"]';
SELECT JSON_SEARCH(@json, 'one', 'abc');

----------
| "$[3]" |
----------

...但是当我明确搜索数字值时,我得到 NULL?

# Number Search Example

SET @json = '[1, 2, 3, "abc"]';
SELECT JSON_SEARCH(@json, 'one', 1);

----------
| NULL   |
----------

奇怪的是JSON_CONTAINS 仍然可以按预期处理数字或字符串。


这可能类似于这个问题-> MYSQL Triggers: JSON_SEARCH an integer value in a json array of integers

【问题讨论】:

    标签: mysql arrays json


    【解决方案1】:

    JSON_SEARCH 函数仅适用于文档中提到的字符串标量:Functions That Search JSON Values

    在这里你可以看到:

    报告的错误 - JSON_SEARCH does not search for non-string values

    报告的功能 - Make JSON_SEARCH work for non-strings

    【讨论】:

      猜你喜欢
      • 2017-03-14
      • 1970-01-01
      • 2023-01-16
      • 1970-01-01
      • 2019-03-30
      • 2016-01-20
      • 2019-02-02
      • 1970-01-01
      • 2017-12-03
      相关资源
      最近更新 更多