How to do a Case Insensitive search on Azure DocumentDb?

独自空忆成欢 提交于 2019-12-17 19:37:48

问题


is it possible to perform a case insensitive search on DocumnetDb?

Let's say I have a record with 'name' key and value as "Timbaktu"

This will work:

select * from json j where j.name  = "Timbaktu"

This wont:

select * from json j where j.name  = "timbaktu"

So how do yo do a case insensitive search?

Thanks in advance.

Regards.


回答1:


There are two ways to do this. 1. use the built-in LOWER/UPPER function, for example,

select * from json j where LOWER(j.name) = 'timbaktu'

This will require a scan though. Another more efficient way is to store a "canonicalized" form e.g. lowercase and use that for querying. For example, the JSON would be

{ name: "Timbaktu", nameLowerCase: "timbaktu" }

Then use it for querying like:

select * from json j WHERE j.nameLowerCase = "timbaktu"

Hope this helps.




回答2:


Perhaps this is an ancient case, I just want to provide a workaround.

You could use UDF in azure cosmos db.

udf:

function userDefinedFunction(str){
    return str .toLowerCase();
}

And use below sql to query results:

SELECT c.firstName FROM c where udf.lowerConvert(c.firstName) = udf.lowerConvert('John')



来源:https://stackoverflow.com/questions/30512806/how-to-do-a-case-insensitive-search-on-azure-documentdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!