Re: Using regular expressions in LIKE - Mailing list pgsql-general

From Tom Lane
Subject Re: Using regular expressions in LIKE
Date
Msg-id 22683.1074184091@sss.pgh.pa.us
Whole thread Raw
In response to Re: Using regular expressions in LIKE  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List pgsql-general
Karsten Hilbert <Karsten.Hilbert@gmx.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

pgsql-general by date:

Previous
From: Terry Lee Tucker
Date:
Subject: Re: Foreign key question
Next
From: Melanie Bergeron
Date:
Subject: problem starting postmaster as a service