Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"

like image 941
G3z Avatar asked Dec 28 '14 22:12

G3z


1 Answers

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.

like image 147
G3z Avatar answered Sep 19 '22 12:09

G3z