Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1D98C475B33 for ; Sat, 10 Aug 2002 14:10:18 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 87A884758D8 for ; Sat, 10 Aug 2002 14:10:17 -0400 (EDT) Received: from [63.195.55.98] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.9) with HTTP id 1607387; Sat, 10 Aug 2002 11:10:16 -0700 From: "Josh Berkus" Subject: Re: getting ILIKE or ~* to use indexes.... To: "Rajesh Kumar Mallah." , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.9 Date: Sat, 10 Aug 2002 11:10:16 -0700 Message-ID: In-Reply-To: <200208101143.54041.mallah@trade-india.com> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/177 X-Sequence-Number: 9023 Rajesh, > I want my query to use indexes for company name searches but its not > happening unless > is use '=' which does not server the purpose. > > eg > > tradein_clients=# explain SELECT co_name FROM unified_data where > co_name ilike '%rajesh%' ; Well, for an *anchored* case-insensitive search, you can create an index on lower(field_name) to use an index. CREATE INDEX idx_uni_co_name ON unifed_data(lower(co_name)); SELECT co_name FROM unified_data where lower(co_name) LIKE (lower('rajesh') || '%') ; And that will use the index. However, what you are doing is an *unanchored* text search, meaning that you are searching for 'rajesh' anywhere in the field. No standard index can help you with that. Instead, you should look into Full Text Search tools. There's a simple one in /contrib in the Postgresql source, and an more robust one available from the OpenFTS project. -Josh Berkus