Re: Best way to use indexes for partial match at beginning

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Best way to use indexes for partial match at beginning
Дата
Msg-id 20051109210810.GF713@svana.org
обсуждение исходный текст
Ответ на Re: Best way to use indexes for partial match at beginning  ("Andrus" <eetasoft@online.ee>)
Ответы Re: Best way to use indexes for partial match at beginning  ("Dean Gibson (DB Administrator)" <postgresql4@ultimeth.com>)
Список 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.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: Best way to use indexes for partial match at
Следующее
От: Jaime Casanova
Дата:
Сообщение: Re: Best way to use indexes for partial match at beginning