【问题标题】:sqlite collate nocase search inside jsonsqlite在json中整理nocase搜索
【发布时间】:2020-09-27 05:12:18
【问题描述】:
我对国家表有一个查询。它具有 json 类型的“数据”。
select country.countryNo,country.population
from country
where json_extract(country.data,'$."stateCount"')="23" COLLATE NOCASE ;
当模型内部的 json 有 Statecount 而不是 stateCount 时,这无法给我结果
我用错了 COLLATE NOCASE 吗?
【问题讨论】:
标签:
sql
json
sqlite
select
where-clause
【解决方案1】:
您误解了COLLATE NOCASE 的目的。它实际上适用于前面的比较运算符(此处为'=')。因此,在您的查询中,它会将 json_extract() 的返回值与 '23' 不区分大小写进行比较 - 正如您所同意的那样,这并没有什么区别。
另一方面,json 键本质上是区分大小写的。如果要搜索具有不同大小写的 json 键,则需要枚举它们:
where
json_extract(country.data,'$.stateCount') = 23
or json_extract(country.data,'$.StateCount') = 23
旁注:如果给定键下的json值数据是数字,json_extract()给你一个数字值,你可以直接和数字比较。