Re: SQL optimization - WHERE SomeField STARTING WITH ...

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Bill <pg(at)dbginc(dot)com>
Cc: PgSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL optimization - WHERE SomeField STARTING WITH ...
Date: 2008-09-01 13:42:29
Message-ID: 48BBF145.1060107@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bill wrote:
> The SQL database servers I have worked with cannot use and index for a
> SELECT of the form
>
> SELECT * FROM ATABLE
> WHERE AFIELD LIKE ?
>
> because there is no way to know the location of the wild card until the
> parameter value is known. InterBase and Firebird allow
>
> SELECT * FROM ATABLE
> WHERE AFIELD STARTING WITH ?
>
> which is equivalent to LIKE 'ABC%' and will use an index on AFIELD. Is
> there a similar syntax in PostgreSQL?

One workaround might be to rewrite the query using some string function
(substring, position, or write your own) and index over that function.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2008-09-01 13:43:42 Re: determining existence of database and language
Previous Message Peter Eisentraut 2008-09-01 13:35:50 Re: indexes on functions and create or replace function