Re: LIKE vrs ~~ - Mailing list pgsql-sql

From Tom Lane
Subject Re: LIKE vrs ~~
Date
Msg-id 6560.960146351@sss.pgh.pa.us
Whole thread Raw
In response to LIKE vrs ~~  ("T.J.Farrell" <T.J.Farrell@wanadoo.fr>)
List pgsql-sql
"T.J.Farrell" <T.J.Farrell@wanadoo.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


pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: LIKE vrs ~~
Next
From: "Rob S."
Date:
Subject: Default timestamp value