MySQLdb compare lower

Frank Millman frank at
Fri Dec 14 07:13:49 CET 2012

On 14/12/2012 06:16, Chris Angelico wrote:
> Yeah, it's one of the things that tripped me up when I did a
> MySQL->PostgreSQL conversion earlier this year. The code was assuming
> case insensitivity, and began failing on PG. Fortunately the simple
> change of LIKE to ILIKE solved that.
> I'd MUCH rather be explicit about wanting case insensitivity.

Just as a side-note, for those who may be interested -

PostgreSQL allows you to create an index using an expression.

Therefore you can say -

   CREATE INDEX ndx ON table_name (LOWER(col_name))

Then you can SELECT ... WHERE LOWER(col_name) = LOWER(%s), and it will 
use the index, so it is not necessary to coerce the data to lower case 
before storing.

Frank Millman

More information about the Python-list mailing list