Note: This is for MySQL 5.7.
When I attempt to use JSON_SEARCH to find the path to a number value within a JSON array, I get NULL. But when I use JSON_SEARCH to look for a string, I actually get the path.
# String Search Example
SET @json = '[1, 2, 3, "abc"]';
SELECT JSON_SEARCH(@json, 'one', 'abc');
----------
| "$[3]" |
----------
Run Code Online (Sandbox Code Playgroud)
...but when I explicitly search for a number value, I get NULL?
# Number Search Example
SET @json = '[1, 2, 3, "abc"]';
SELECT JSON_SEARCH(@json, 'one', 1);
----------
| NULL |
----------
Run Code Online (Sandbox Code Playgroud)
What's strange is that JSON_CONTAINS still works as intended with numbers or strings.
This may be similar to this question -> MYSQL Triggers: JSON_SEARCH an integer value in a json array of integers
JSON_SEARCH函数仅适用于文档中提到的字符串标量:搜索 JSON 值的函数
在这里你可以看到:
报告的错误 - JSON_SEARCH 不搜索非字符串值
报告的功能 -使 JSON_SEARCH 适用于非字符串