Search code examples
ruby-on-railspostgresqlcase-insensitivesql-like

Postgres case insensitive searching with Rails


My development database is SQLite but I deploy my app to Heroku and they are using PostgreSQL.

Now sometimes I have two different results coming out if I perform searches because PostgreSQL is case-sensitive but SQLite is not.

Shouldn't Rails standardize these things? What methods should I use to solve that?

Here is how to fix it with raw SQL


Solution

  • Case insensitive searching in Postgres:

    • use ilike instead of like (case-insensitive like)
    • if you want to use =, make both sides either UPPER or LOWER