Re: Using regular expressions in LIKE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
Cc: "'Pgsql-General(at)Postgresql(dot)Org (E-mail)'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using regular expressions in LIKE
Date: 2004-01-15 16:28:11
Message-ID: 22683.1074184091@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> writes:
>> Regexes are optimized the same way as equivalent LIKE expressions. In
>> particular, the pattern has to be left-anchored to consider using it
>> with an index. In LIKE that means no wildcard at the start of the
>> pattern, in regex it means there has to be a ^.

> What about "^.*oobar" in a regex ? I mean, it seems impossible
> to use an index on that, right ?

Right. You need ^ immediately followed by some constant text. The
planner extracts the "fixed prefix" of the pattern to use with the index.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Melanie Bergeron 2004-01-15 16:33:31 problem starting postmaster as a service
Previous Message Julio Misael Gutierrez 2004-01-15 16:22:20 when I create a table, postgresql creates a new type