I am trying to query a Postgres Array Column disregarding case and perhaps even disregarding spaces as well.
SELECT "cats".* FROM "cats" WHERE ('CATS - PERSA' = ANY(UPCASE(cat_types))) ORDER BY "cats"."id" ASC LIMIT 1;
But I get this error:
You might need to add explicit type casts.
AS a bonus I would like to also be able to do a regexp where the search ignores spaces in values on the cat_types column.
I am using Ruby on Rails to do this.
cat_type.upcase.delete(' ')
Cats.where("'#{cat_type}' = ANY(cat_types)").first
The query works just using ANY but I want to be able to disregard spaces and upcase the values in cat_types so that it has more chances of matching. Ilike could also be a possibility.
Thanks.
'CATS - PERSA' ~* ANY(cat_types)
? It will do case-insensitive regexp mach. – Igor Romanchenko Apr 9 at 20:08this
page. It could be usefull to get some time and read the full manual - it has alot of nice things you do not know about. – Igor Romanchenko Apr 9 at 20:28\d tbl
inpsql
) . – Erwin Brandstetter Apr 9 at 21:35