Re: Best way to use indexes for partial match at beginning - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Best way to use indexes for partial match at beginning
Date
Msg-id 20051109210810.GF713@svana.org
Whole thread Raw
In response to Re: Best way to use indexes for partial match at beginning  ("Andrus" <eetasoft@online.ee>)
Responses Re: Best way to use indexes for partial match at beginning  ("Dean Gibson (DB Administrator)" <postgresql4@ultimeth.com>)
List pgsql-general
On Wed, Nov 09, 2005 at 10:46:27PM +0200, Andrus wrote:
> thank you. I try to formulate my problem more presicely.
> I have table
>
> CREATE TABLE foo ( bar CHAR(10)  PRIMARY KEY);
>
> Cluster locale is non-C. Database encoding is UTF-8. Postgres vers is 8.1

Do this instead:

CREATE TABLE foo ( bar CHAR(10) NOT NULL );
CREATE UNIQUE INDEX foo_bar ON foo(bar char_pattern_ops);

> I want to run fast queries by knowing first characters of bar like :
>
> 1. Select records from foo where first character of bar is A
> 2. Select records from foo where first character of bar is B
> 3. Select records from foo where first  two characters of bar are BC
> 4. Select records from foo where first  three characters of bar are ABC

SELECT * FROM foo WHERE bar LIKE 'A%';
SELECT * FROM foo WHERE bar LIKE 'B%';
SELECT * FROM foo WHERE bar LIKE 'BC%';
SELECT * FROM foo WHERE bar LIKE 'ABC%';

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: Best way to use indexes for partial match at
Next
From: Jaime Casanova
Date:
Subject: Re: Best way to use indexes for partial match at beginning