| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | zxwsbg12138(at)gmail(dot)com |
| Subject: | BUG #19474: LIKE with nondeterministic collations mis-handle literal backslashes in patterns containing escape |
| Date: | 2026-05-09 02:22:23 |
| Message-ID: | 19474-5b86a95f3d9a7ecb@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19474
Logged by: Bowen Shi
Email address: zxwsbg12138(at)gmail(dot)com
PostgreSQL version: 18.3
Operating system: centos
Description:
After commit 85b7efa1cdd63c2fe2b70b725b8285743ee5787f ("Support LIKE with
nondeterministic collations"), LIKE on a nondeterministic collation can
return an incorrect result when the pattern contains a literal backslash.
The problem appears to be in MatchText() in
src/backend/utils/adt/like_match.c. In the nondeterministic-collation path,
when a pattern substring contains escape processing, the code builds an
unescaped copy of the substring. In that logic, a backslash that should
remain as a literal character can be dropped, so the substring compared by
pg_strncoll() is not the same as the original SQL pattern semantics.
As a result, a LIKE pattern that should match a string containing a literal
backslash can incorrectly return false.
SQL reproduction:
CREATE COLLATION ignore_accents (
provider = icu,
locale = 'und-u-ks-level1',
deterministic = false
);
SELECT 'back\slash' COLLATE ignore_accents LIKE 'back\slash%' ESCAPE '#';
Expected result:
t
Actual result:
f
The same pattern works as expected without the nondeterministic collation
semantics.
A table-based reproduction:
CREATE COLLATION ignore_accents (
provider = icu,
locale = 'und-u-ks-level1',
deterministic = false
);
CREATE TABLE like_test (val text);
INSERT INTO like_test VALUES ('back\slash');
SELECT val
FROM like_test
WHERE val COLLATE ignore_accents LIKE 'back\slash%' ESCAPE '#';
Expected result:
one row: back\slash
Actual result:
zero rows
This seems to be caused by the unescape logic in like_match.c for
nondeterministic collations, where a pattern fragment containing backslashes
is copied incorrectly before calling pg_strncoll().
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PG Bug reporting form | 2026-05-11 07:41:42 | BUG #19475: VACUUM on a partition still warns after MAINTAIN is granted on the partitioned parent |
| Previous Message | Michael Paquier | 2026-05-08 23:07:06 | Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum |