Re: LIKE vrs ~~

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: LIKE vrs ~~
Дата
Msg-id 6560.960146351@sss.pgh.pa.us
обсуждение исходный текст
Ответ на LIKE vrs ~~  ("T.J.Farrell" <T.J.Farrell@wanadoo.fr>)
Список 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 по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: LIKE vrs ~~
Следующее
От: "Rob S."
Дата:
Сообщение: Default timestamp value