Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input - Mailing list pgsql-bugs

From shihao zhong
Subject Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input
Date
Msg-id CAGRkXqS3zxLWfmTF3q4oe7hunOqAAjjFMa_PB2Dvzjo7P3a5Hw@mail.gmail.com
Whole thread
In response to BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input
List 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

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19719: BUG: huge_pages=on shared memory reattached without FILE_MAP_LARGE_PAGES on Windows
Next
From: Tom Lane
Date:
Subject: Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input