| From: | shihao zhong <zhong950419(at)gmail(dot)com> |
|---|---|
| To: | imchifan(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input |
| Date: | 2026-09-25 04:59:59 |
| Message-ID: | CAGRkXqS3zxLWfmTF3q4oe7hunOqAAjjFMa_PB2Dvzjo7P3a5Hw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
Same issue as bug #18765 [1]. The trailing escape check only runs when
matching reaches the end of the pattern, so 'x' LIKE 'y\' and
'x' LIKE 'x\' also return false.
Tom's concern there was the cost of an extra pass over the pattern. We
don't need one. A pattern ends with an escape exactly when it ends with
an odd number of backslashes, so the check looks at the last byte and
usually stops there. The attached patch does that at the top of
MatchText(). 0002 adds tests and is optional.
Master only, I think, since some queries that return false today will
now fail.
The planner still reads 'abc\' as an exact match for 'abc'. So an index
scan that finds no 'abc' rows returns nothing instead of failing. I left
that alone, but can make like_fixed_prefix() throw too if wanted.
[1] https://postgr.es/m/18765-6c26d2047e6f5143@postgresql.org
Thanks,
Shihao
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Reject-LIKE-patterns-that-end-with-an-escape-what.patch | application/octet-stream | 2.7 KB |
| v1-0002-Add-tests-for-LIKE-patterns-that-end-with-an-esca.patch | application/octet-stream | 2.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-09-25 05:05:54 | Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input |
| Previous Message | PG Bug reporting form | 2026-09-25 04:39:16 | BUG #19719: BUG: huge_pages=on shared memory reattached without FILE_MAP_LARGE_PAGES on Windows |