我希望使用 json_search 来获取对应于某个值的数组路径。
我试过了,这个有效:
SET @j = '["3", "2", "1"]';
SELECT json_search(@j, 'one', '2');
返回 $[1];
我已经尝试过了,但这行不通:(我该如何让它工作?)
SET @j = '[3, 2, 1]';
SELECT json_search(@j, 'one', 2);
返回空;
基本上我想将@j 存储为整数数组而不是字符串数组以用于索引目的。如果 json_search 无法使用整数,有什么方法可以将整数数组更改为字符串数组以进行比较?
最佳答案
这是设计使然,尽管我不同意 mySQL 团队的观点。这应该实现。
https://bugs.mysql.com/bug.php?id=79233
The specification at https://dev.mysql.com/worklog/task/?id=7909 says: "This function returns path(s) to the given string. The returned path(s) identify object members or array slots which are character strings."
So it seems that the intention of this function was to search for strings. The documentation should be updated to clarify that the function is for searching for string scalars, not for scalars in general.
关于MYSQL 触发器 : JSON_SEARCH an integer value in a json array of integers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40356672/