Re: LIKE vrs ~~

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "T(dot)J(dot)Farrell" <T(dot)J(dot)Farrell(at)wanadoo(dot)fr>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: LIKE vrs ~~
Date: 2000-06-04 19:19:11
Message-ID: 6560.960146351@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"T.J.Farrell" <T(dot)J(dot)Farrell(at)wanadoo(dot)fr> writes:
> I was wondering about the performance incidence of :
> SELECT * FROM table1 WHERE UPPER(field1) LIKE
> UPPER('%thomas%');
> versus:
> SELECT * FROM table1 WHERE field1 ~~ '%thomas%'

Of course "~~" is just an alternate spelling of LIKE, and is
case-sensitive, so the above two queries are not equivalent.
Perhaps you meant to refer to "~*" which is a case-insensitive
regex match ... but then you'd need a different pattern.

Anyway, if you keep an index on upper(field1) then the first form
is the way to go, since the system can use a left-anchored pattern
as an index range restriction.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rob S. 2000-06-05 07:34:47 Default timestamp value
Previous Message Peter Eisentraut 2000-06-04 01:46:22 Re: LIKE vrs ~~