MYSQL 触发器:JSON_SEARCH json 整数数组中的整数值
我希望使用 json_search 来获取与值对应的数组路径.
I am looking to use json_search to get the array path that corresponds to a value.
我试过了,这很有效:
SET @j = '["3", "2", "1"]';
SELECT json_search(@j, 'one', '2');
返回 $[1];
我已经尝试过,但这不起作用:(我如何使它起作用?)
I have tried and this doesn't work: (How do I make this work?)
SET @j = '[3, 2, 1]';
SELECT json_search(@j, 'one', 2);
返回空值;
基本上我想将@j 存储为一个整数数组而不是一个用于索引目的的字符串数组.如果 json_search 无法使用整数,有什么方法可以将整数数组更改为字符串数组进行比较?
Basically I want to store @j as an integer array instead of a string array for indexing purposes. Is there any way I can change the integer array into a string array for comparison if there is no way for json_search to work with integers?
推荐答案
这是设计使然,虽然我不能同意 mySQL 团队的意见.这应该被实施.
It is by design, although I can not agree with mySQL team. This should be implemented.
https://bugs.mysql.com/bug.php?id=79233 [关闭]
https://dev.mysql.com/worklog/task/中的规范?id=7909 说:"此函数返回给定字符串的路径.返回的路径标识作为字符的对象成员或数组槽字符串."
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.
相关文章