Querying a Postgres array of integers in Rails
Try these:
MyModel.where("? = ANY(myarray)", '{42}')
or
MyModel.where("myarray @> ?", '{42}')
or (on PG 9.6 according to York Yang's comment)
MyModel.where("? = ANY(myarray)", '42')
PG::UndefinedFunction: ERROR: operator does not exist: integer = text
From this message it appears that the myarray
is actually an array of type text
. Check that column to make sure it is of the correct type.
seems to had a problem with the name of the array since there was an association with a similar name and rails automagic collided with it