Re: Using regular expressions in LIKE

From: "Nick Barr" <nick(dot)barr(at)webbased(dot)co(dot)uk>
To: "'Patrick Welche'" <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
Cc: <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 12:22:32
Message-ID: 8F4A22E017460A458DB7BBAB65CA6AE502AA48@openmanage
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-
> owner(at)postgresql(dot)org] On Behalf Of Patrick Welche
> Sent: 15 January 2004 12:09
> To: Nick Barr
> Cc: csegyud(at)vnet(dot)hu; terry(at)ashtonwoodshomes(dot)com; 'Pgsql-
> General(at)Postgresql(dot)Org (E-mail)'
> Subject: Re: [GENERAL] Using regular expressions in LIKE
>
> On Thu, Jan 15, 2004 at 09:05:35AM -0000, Nick Barr wrote:
> > If the ^ was not there then it could theoretically match anywhere in
the
> > string. In this particular case the regular expression will probably
> > match at the beginning of the string anyway, so it is not really
> > necessary. I prefer to put that sort of thing in to make it clear to
the
> > programmer what is going on.
>
> 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 certainly the case with queries that use the LIKE operator, for
example:

where adate like 'random%';

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?

Nick

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2004-01-15 13:31:21 Re: Bug and/or feature? Complex data types in tables...
Previous Message Curt Sampson 2004-01-15 12:14:23 Solution to UPDATE or INSERT Problem