Database Case Insensitive Index?

前端 未结 6 1171
无人及你
无人及你 2021-01-12 16:30

I have a query where I am searching against a string:

SELECT county FROM city WHERE UPPER(name) = \'SAN FRANCISCO\';

Now, this works fine,

6条回答
  •  爱一瞬间的悲伤
    2021-01-12 17:09

    Short answer, no.

    Long answer, yes if you're running on the mainframe, but you're not, so you have to use other trickery.

    DB2 (as of DB2/LUW v8) now has generated columns so you can:

    CREATE TABLE tbl (
        lname  VARCHAR(20),
        fname  VARCHAR(20),
        ulname VARCHAR(20) GENERATED ALWAYS AS UPPER(lname)
    );
    

    and then create an index on ulname. I'm not sure you're going to get it simpler than that.

    Before that, you used to have to use a combination of insert and update triggers to ensure the ulname column was kept in sync, and this was a nightmare to maintain. Also, now that this functionality is part of the core DBMS, it's been highly optimized (it's much faster than the trigger-based solution) and doesn't get in the way of real user triggers, so no extra DB objects to maintain.

    See here for details.

提交回复
热议问题