Re: Use index for upper(customername) like 'ABC%'

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "T(dot)J(dot) Adami" <adamitj(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Use index for upper(customername) like 'ABC%'
Date: 2008-02-18 16:37:46
Message-ID: 162867790802180837h5c6b4b83n22ceedd1ae8a92cf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

if you have non-c locale, you have to use varchar_pattern_ops - like:

create index like_index on lidi (prijmeni varchar_pattern_ops);

Regards
Pavel Stehule

On 18/02/2008, T.J. Adami <adamitj(at)gmail(dot)com> wrote:
> On 4 fev, 18:13, "Andrus" <kobrule(dot)(dot)(dot)(at)hot(dot)ee> wrote:
> > I need to perform case insensitive search by first some characters (ABC) of
> > name like
> >
> > SELECT ...
> > FROM customer
> > WHERE upper(customername) like 'ABC%'
> >
> > My database cluster locale is non-C
> > Database encoding is UTF-8
> >
> > Which index I must create so that this query can use it to speed up data
> > retrieval ?
> >
> > Andrus.
>
> CREATE INDEX ie_cust_upper_name ON customer ( UPPER( customername ) );
>
> If you want to perform better performance for "like 'ABC%'" statement,
> you can define it on WHERE clause:
>
> CREATE INDEX ie_cust_upper_name ON customer ( UPPER( customername ) )
> WHERE ( UPPER(customername) LIKE 'ABC%' );
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2008-02-18 16:40:51 Re: nntp interface not working?
Previous Message fdu.xiaojf@gmail.com 2008-02-18 16:37:13 questions about very large table and partitioning