Re: postgres index on ILIKE - Mailing list pgsql-sql

From Josh Berkus
Subject Re: postgres index on ILIKE
Date
Msg-id 200309291002.14823.josh@agliodbs.com
Whole thread Raw
List pgsql-sql
Alex,

> I read your article about indexing in postgres which unfortunately ends
> after the 2nd part. So I decided to ask you by email.

Yeah, yeah, I know.   The completed version will probably become part of a 
published book.  We'll see.

> Is it somehow possible to create an index for the ILIKE comparision?
> I set up a database which contains the paths to all files in my network
> neighborghood.

Short of creating your own datatype, you can't index for ILIKE.   

Instead, you create an index on the LOWER() of the column ...

CREATE INDEX idx_table_lower_text ON table(lower(text_field));

Then, you make sure when querying to query the lower function:

SELECT * FROM table
WHERE lower(text_field) LIKE 'xxxyy%';

This will use the index wherever it improves execution.

I suggest that you join the PGSQL-SQL mailing list for future questions of 
this type.

-- 
Josh Berkus
Aglio Database Solutions
San Francisco


pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Need to overcome UNION / ORDER BY restriction
Next
From: Evgen Potemkin
Date:
Subject: Re: Oracle 'connect by prior' now eaiser in 7.3?