Yet another bug in nondeterministic LIKE
While studying the reported bug #19474 [1]/messages/by-id/CAH5HC94yU+K8Gcdy12M5BS8gwD_SXLSHzc9k5tNk7JDnpBiFMA@mail.gmail.com, I realized that there's
still another bug with nondeterministic LIKE's handling of escape
characters. If there's an escape at the start of the pattern
(or just after a wildcard), and it's escaping an ordinary character,
we handle that with code that only works for deterministic collations.
This at least gives wrong answers:
u8=# select 'AB' like 'a\b' collate case_insensitive; -- okay
?column?
----------
t
(1 row)
u8=# select 'AB' like '\ab' collate case_insensitive; -- not okay
?column?
----------
f
(1 row)
and it can also result in invoking pg_strncoll() on a partial
multibyte character. I didn't try to build a test case showing
misbehavior from that, but there probably is some.
The fix is pretty simple, just re-order the stanzas in MatchText's
loop. I couldn't resist the temptation to do some additional
janitorial work though.
regards, tom lane
[1]: /messages/by-id/CAH5HC94yU+K8Gcdy12M5BS8gwD_SXLSHzc9k5tNk7JDnpBiFMA@mail.gmail.com