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

后端 未结 11 2112
南方客
南方客 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:02

    In postgres, you can do this:

    SELECT whatever FROM mytable WHERE something ILIKE 'match this';
    

    I'm not sure if there is an equivalent for MySQL but you can always do this which is a bit ugly but should work in both MySQL and postgres:

    SELECT whatever FROM mytable WHERE UPPER(something) = UPPER('match this');
    

提交回复
热议问题