How do you write a case insensitive query for both MySQL and Postgres?

后端 未结 11 2115
南方客
南方客 2020-11-29 23:39

I\'m running a MySQL database locally for development, but deploying to Heroku which uses Postgres. Heroku handles almost everything, but my case-insensitive Like statements

11条回答
  •  天涯浪人
    2020-11-30 00:16

    Use Arel:

    Author.where(Author.arel_table[:name].matches("%foo%"))
    

    matches will use the ILIKE operator for Postgres, and LIKE for everything else.

提交回复
热议问题