user181452 user181452 - 5 months ago 10x
SQL Question

Query Char varying postgres

I've been trying to make the following query works, but I couldn't:

SELECT "users".* FROM "users" WHERE (users.roles LIKE "%sales%")
SELECT "users".* FROM "users" WHERE (users.roles LIKE '%sales%')

where roles, can contain:


and roles is:
character varying[]

I'm getting the error:

ERROR: operator does not exist: character varying[] ~~ unknown LINE
1: select from users where users.roles LIKE '%sales%'...



SELECT "users".* FROM "users" WHERE  'sales' = ANY(users.roles) 

Having said that, it's worth noting:

Tip: Arrays are not sets; searching for specific array elements can be a sign of database misdesign. Consider using a separate table with a row for each item that would be an array element. This will be easier to search, and is likely to scale better for a large number of elements.