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

From: "T(dot)J(dot) Adami" <adamitj(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Use index for upper(customername) like 'ABC%'
Date: 2008-02-18 12:02:13
Message-ID: eaa91b3e-4a9d-42ae-aa13-5f0c0e8c6df8@n77g2000hse.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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%' );

Responses

Browse pgsql-general by date

  From Date Subject
Next Message T.J. Adami 2008-02-18 12:08:09 Re: Order of SUBSTR and UPPER in statement
Previous Message Alexey Nalbat 2008-02-18 10:53:24 deadlock with truncate and foreing keys