Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wLXUb-001qg2-1M for pgsql-bugs@arkaria.postgresql.org; Sat, 09 May 2026 02:32:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wLXUZ-00C1CZ-1O for pgsql-bugs@arkaria.postgresql.org; Sat, 09 May 2026 02:32:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wLXLR-00C0HG-0R for pgsql-bugs@lists.postgresql.org; Sat, 09 May 2026 02:23:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wLXLN-00000000uo3-2xSq for pgsql-bugs@lists.postgresql.org; Sat, 09 May 2026 02:23:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=Tiy21Y2MqZWwFp8VhyFFZLKBSXBNHcocTqPmsYNzMF0=; b=JRZs18kd7zzlr5zlWKzj5J1p6m IROZ5rJlJ2OjvxxebOIL8Ox2w0O/aLyKFTxQH0PcVTxqIJA2LA6PAVaaipPY4qCxG/pxb96kWOHd1 gBQK9rPPew3xZG2yWw/3z2FR7H30aS4oPlQWN3YTesaNJkYzb9gDzwP8WKolaInaZyEAT6tzzsrVj Mqx+yDKYBOut/P0H9Gpa8xEHQR0PfJqXe39NdscofRuDAfCBBLLeCy+XxAPyiOO+2Eu3tgRdFp4Yg Si4PiPByYPK7Aw2j2absjnL/J0lbys40hjOKDqRlaQSnIN97O7KNF4u7VzcADtZ8CAeLHH2mBfyPc wDUNTHOQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wLXLM-002buX-1j for pgsql-bugs@lists.postgresql.org; Sat, 09 May 2026 02:23:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wLXLL-0072nx-0n for pgsql-bugs@lists.postgresql.org; Sat, 09 May 2026 02:23:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19474: LIKE with nondeterministic collations mis-handle literal backslashes in patterns containing escape To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: zxwsbg12138@gmail.com Reply-To: zxwsbg12138@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sat, 09 May 2026 02:22:23 +0000 Message-ID: <19474-5b86a95f3d9a7ecb@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19474 Logged by: Bowen Shi Email address: zxwsbg12138@gmail.com PostgreSQL version: 18.3 Operating system: centos Description: =20 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 =3D icu, locale =3D 'und-u-ks-level1', deterministic =3D 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 =3D icu, locale =3D 'und-u-ks-level1', deterministic =3D 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().