mysql jsonsearch all,使用不区分大小写的搜索(使用MySQL Json_search函数)获取JSON数据内的值的路径表达式...

I have a requirement where by I need to extract JSON path expression from a JSON data searching by a value.

For example if I have the JSON data stored like

SET @j = '[{"name":"Kiran Muralee", "age" : 30 , "Salary" : 30000},

{"Name":"Arun Babu", "age" : 35 , "Salary" : 60000}]';

And if I need to get the JSON Path of value 'Arun Babu' I could use

SELECT JSON_SEARCH(@j, 'all', 'Arun Babu');

This results in

"$[1].Name"

Which is right but the problem is if I search with value 'arun babu', it returns NULL. So to do a case insensitive search I used

SELECT JSON_SEARCH(lower(@j), 'all', lower('arun babu'));

So now I am getting the result as

"$[1].name"

But this is not I needed because now the result also outputted in lower case, I need the result to be

"$[1].Name"

Can anyone suggest a good solution or approach.

MySQL version using is 5.7 (JSON type supported version)

解决方案

We can get the expected solution by using the case insensitive collation:

SELECT JSON_SEARCH(@j , 'all', 'arun babu' COLLATE utf8mb4_general_ci);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值