Database Case Insensitive Index?

前端 未结 6 1170
无人及你
无人及你 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:02

    PostgreSQL also supports indexing the results of a function:

    CREATE INDEX mytable_lower_col1_idx ON mytable (lower(col1));
    

    The only other option I can think of is to de-normalize your data a bit by creating another column to hold the upper-case version (updated by triggers) and index that. Blech!

提交回复
热议问题