Re: MySQLdb compare lower

Discussion in 'Python' started by Frank Millman, Dec 14, 2012.

  1. 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
     
    Frank Millman, Dec 14, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anatoli Hristov

    MySQLdb compare lower

    Anatoli Hristov, Dec 11, 2012, in forum: Python
    Replies:
    2
    Views:
    148
    Anatoli Hristov
    Dec 11, 2012
  2. Cameron Simpson

    Re: MySQLdb compare lower

    Cameron Simpson, Dec 11, 2012, in forum: Python
    Replies:
    0
    Views:
    163
    Cameron Simpson
    Dec 11, 2012
  3. Dennis Lee Bieber

    Re: MySQLdb compare lower

    Dennis Lee Bieber, Dec 12, 2012, in forum: Python
    Replies:
    0
    Views:
    163
    Dennis Lee Bieber
    Dec 12, 2012
  4. Cameron Simpson

    Re: MySQLdb compare lower

    Cameron Simpson, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    166
    Cameron Simpson
    Dec 13, 2012
  5. Dennis Lee Bieber

    Re: MySQLdb compare lower

    Dennis Lee Bieber, Dec 13, 2012, in forum: Python
    Replies:
    0
    Views:
    159
    Dennis Lee Bieber
    Dec 13, 2012
Loading...

Share This Page