[PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
Nitin Motiani <nitinmotiani@google.com>
From: Nitin Motiani <nitinmotiani@google.com>
To: pgsql-hackers@postgresql.org
Date: 2026-05-14T11:12:33Z
Lists: pgsql-hackers
Attachments
- v1-0001-Fix-LIKE-matching-with-nondeterministic-collation.patch (application/x-patch) patch v1-0001
It was reported in [1] that LIKE on a non-deterministic collation returns an incorrect result when the pattern contains a literal backslash. This was caused by escaping all backslashes in like_match.c (even when the internal pattern contained '\\'). This behaviour has been present since 85b7efa1cd which originally added support for LIKE with non-deterministic collations. This patch fixes the issue by always including the character after a literal '\' in the final buffer. I didn't check for the end of the string because that check is already handled in the block above when checking for escape characters. I also added a regression test for this issue and confirmed that it passes with the fix. Please take a look and let me know what you folks think. [1] https://www.postgresql.org/message-id/flat/19474-5b86a95f3d9a7ecb%40postgresql.org Thanks & Regards, Nitin Motiani Google