[PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations

From: Nitin Motiani <nitinmotiani(at)google(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] Fix for bug #19474: LIKE fails to match literal backslashes with nondeterministic collations
Date: 2026-05-14 11:12:33
Message-ID: CAH5HC94yU+K8Gcdy12M5BS8gwD_SXLSHzc9k5tNk7JDnpBiFMA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
v1-0001-Fix-LIKE-matching-with-nondeterministic-collation.patch application/x-patch 3.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message r314tive 2026-05-14 11:19:45 [RFC PATCH v1] Add EXPLAIN ANALYZE wait event reporting
Previous Message shveta malik 2026-05-14 11:06:18 Re: synchronized_standby_slots behavior inconsistent with quorum-based synchronous replication