Re: Using regular expressions in LIKE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Nick Barr" <nick(dot)barr(at)webbased(dot)co(dot)uk>
Cc: "'Patrick Welche'" <prlw1(at)newn(dot)cam(dot)ac(dot)uk>, csegyud(at)vnet(dot)hu, terry(at)ashtonwoodshomes(dot)com, "'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 15:15:41
Message-ID: 22128.1074179741@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Nick Barr" <nick(dot)barr(at)webbased(dot)co(dot)uk> writes:
>> Isn't there also a performance benefit as you can use an index if you
>> say "this definitely starts at the beginning" with the '^'?

> That is what I was thinking, which is the other reason why I put it in.
> This is only the case with the default locale I believe. I have no idea
> when it comes to regexs though and specifically the ~ operator. Could
> someone more knowledgeable about this stuff reply?

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 ^.

Locale and case sensitivity issues are the same, too.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Uros 2004-01-15 15:22:45 Re: parse error in function
Previous Message Marc G. Fournier 2004-01-15 15:14:38 Re: Mailing list? was Postgress and MYSQL