Re: postgres index on ILIKE

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Alex Kretschmer <a_kretschmer(at)gmx(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: postgres index on ILIKE
Date: 2003-09-29 17:02:14
Message-ID: 200309291002.14823.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-09-29 17:09:31 Re: postgres index on ILIKE
Previous Message Richard Huxton 2003-09-29 16:52:39 Re: SRF Functions don't want to return empty tuple