how do I perform a case-insensitive search in a Postgres 9.4 JSONB column?

喜夏-厌秋 提交于 2019-12-04 23:50:52

问题


i'm using this query to look for data in a table where profile is a JSONB column and it works but only if the name is exactly that

SELECT * FROM "users" WHERE "profile" @> '{"name":"Super User"}'

is it possible to have more flexibility like case insensitivity, wildcards and so on ?

Something like "Super%" or "super user"


回答1:


I found the solution to my problem:

SELECT * FROM "users" WHERE (profile #>> '{name}') ILIKE 'super %'

I don't know if this is performing well enough but it works.
Probably it's wise to add an index to it.



来源:https://stackoverflow.com/questions/27681163/how-do-i-perform-a-case-insensitive-search-in-a-postgres-9-4-jsonb-column

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