# MySQL in dev, Postgres in prod - differences in "LIKE" query

**URL:** <https://www.ruby-forum.com/t/mysql-in-dev-postgres-in-prod-differences-in-like-query/90214>\
**Category:** Rails\
**Created:** [March 29, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/mysql-in-dev-postgres-in-prod-differences-in-like-query/90214 "2006-03-29T21:25:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [March 29, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/mysql-in-dev-postgres-in-prod-differences-in-like-query/90214/1 "2006-03-29T21:25:41Z")

</div>

Hi everyone,

I run MySQL in my dev environment, but Postgres in my production  
environment (out of necessity). I’m having trouble finding a way to  
write a query with a LIKE condition that is supported as case  
insensitive in both databases.

Right now, I have this:

@query = “m” # for example  
@people = Person.find(:all, :conditions =\> [“last\_name LIKE ?”, @query +  
“%”])

This works in MySQL, but in Postgres, it’s case sensitive. If I  
change it to support the Postgres syntax, it doesn’t work in MySQL.  
Is there a more Rails way to handle this?

Thanks!

Sean

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [March 29, 2006, 10:32pm UTC](https://www.ruby-forum.com/t/mysql-in-dev-postgres-in-prod-differences-in-like-query/90214/2 "2006-03-29T22:32:45Z")

</div>

Postgres uses “ilike” for insensetive “like” comparisons. Maybe mysql  
uses it too.

Alternatively, maybe you can force the query string to lowercase in  
ruby, and use something like “LOWER(last\_name) LIKE ?”

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [March 29, 2006, 11:09pm UTC](https://www.ruby-forum.com/t/mysql-in-dev-postgres-in-prod-differences-in-like-query/90214/3 "2006-03-29T23:09:09Z")

</div>

On Wed, 2006-03-29 at 14:04 -0500, Sean H. wrote:

> @people = Person.find(:all, :conditions =\> [“last\_name LIKE ?”, @query + “%”])
> 
> This works in MySQL, but in Postgres, it’s case sensitive. If I  
> change it to support the Postgres syntax, it doesn’t work in MySQL.  
> Is there a more Rails way to handle this?

* * *

can you use @query.downcase instead of @query?

Don’t you need “%” + @query.downcase + “%” #percent symbol on both  
sides?

Craig

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [March 29, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/mysql-in-dev-postgres-in-prod-differences-in-like-query/90214/4 "2006-03-29T23:54:36Z")

</div>

That’ll work! I checked around more and I couldn’t find a Rails way to  
do it.

Thank you!

Sean
