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

From Stephan Szabo
Subject Re: Best way to use indexes for partial match at
Date
Msg-id 20051111072537.W1473@megazone.bigpanda.com
Whole thread Raw
In response to Re: Best way to use indexes for partial match at  ("Andrus" <eetasoft@online.ee>)
List pgsql-general
On Fri, 11 Nov 2005, Andrus wrote:

> >> SELECT * FROM foo WHERE bar::CHAR(3)='ABC';
>
> > Your query is the same as using LIKE, so why not express it that way?
>
> I want simply to select by first 3 characters. LIKE is too powerful and
> unnessecary. LIKE requires
> escaping % and ? characters in pattern.
>
> I expected that making planner to use primary key index in case of
>
> WHERE bar::CHAR(3)='ABC'
> WHERE bar BETWEEN 'ABC' AND 'ABC' || CHR(255)
> WHERE SUBSTRING( bar FOR 3 )='ABC'

Which doesn't necessarily work because of how some collations may work.
The first 3 characters of the string may sort to a fundamentally different
place than the first 4 characters. You can have a collation where
'ABC' < 'ABCR' < 'ABCT' < 'ABD' < 'ABZ' < 'ABCS'.  In the above, the ABCS
value shortens so it should be found, however it's sort position in the
index is outside the normal ABC range. AFAIK the interfaces being used
don't give enough information to detect such locales to handle them
differently.

pgsql-general by date:

Previous
From: Jaime Casanova
Date:
Subject: Re: Best way to use indexes for partial match at
Next
From: "Florian G. Pflug"
Date:
Subject: I'm getting "ERROR: unsupported type: 17296"