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

From: "Dean Gibson (DB Administrator)" <postgresql4(at)ultimeth(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Best way to use indexes for partial match at beginning
Date: 2005-11-09 21:23:44
Message-ID: 437268E0.808@ultimeth.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2005-11-09 13:08, Martijn van Oosterhout wrote:
>> 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,
>

Or:

SELECT * FROM foo WHERE bar::CHAR(1) = 'A';
SELECT * FROM foo WHERE bar::CHAR(1) = 'B';
SELECT * FROM foo WHERE bar::CHAR(2) = 'BC';
SELECT * FROM foo WHERE bar::CHAR(3) = 'ABC';

-- Dean

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2005-11-09 21:30:47 Re: Best way to use indexes for partial match at
Previous Message rm_pg 2005-11-09 21:20:27 set-valued function difference in 8.1.0 vs 8.0.2