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 1vQTBT-008GWM-0w for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Dec 2025 16:24:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vQTBS-008w2q-1J for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Dec 2025 16:24:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vQTBS-008w2i-0Q for pgsql-bugs@lists.postgresql.org; Tue, 02 Dec 2025 16:24:58 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vQTBQ-002lTR-2O for pgsql-bugs@lists.postgresql.org; Tue, 02 Dec 2025 16:24:58 +0000 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-640a3317b89so8981563a12.0 for ; Tue, 02 Dec 2025 08:24:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1764692695; x=1765297495; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=XNRl5S/JDWPdwNBZghmQ/IdZHRCevUv8cTQSssjpJvQ=; b=cV34wbzpJIxAPI73Ys6vb9eNZw3hIqF38lp2+i54DjYpeGoXpDv+zkD5yEAKuznJMc jHKB4Vj92RNuczoWQ6m9RdHk6W+c/fi6dkykgg+dylSEtYjBA4LNeoXrb5kmfXugq9ie 7spQnx+T5hY7HXjIAVmDRrXMeH2I1A0x8e3SsiU9X/qRk0QxYPjtjA8OStQdgZ690r2j mDoim5fBJ29h2XgNx2s73Liwr5mqtS9O/Z153oXMJcr/dkb1+H7H9xYjx5F4UiLrUOCo PVHYkS3HawKuz+dty69AvBqJiPb6B/CCjRuMvfAvJHvWtKT1cOtK2LL1fGrT+8aHLBPq d5FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764692695; x=1765297495; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XNRl5S/JDWPdwNBZghmQ/IdZHRCevUv8cTQSssjpJvQ=; b=M6rF/IM2k+2aflCBHBRvGAj2TuGZRq6BaoUkNmH4WshDFQCFj6gaLVew8yzNzamYhy wncFGkMlHaR1FbHHCXsDuvJygVx9Spw38choiLzT9Z6hdcXHVFxS+GNuwudhDkQWG/gI Xz1cY4Z2RaiUGp3/Zp5Le+Fuuoqg7YrzTK+6wnvirHnRHLEaC7FL7kDtT/bqalcM8tKt yvpC1+Ugk8gF5xP7y0TEQXZma7ca15U6YF+nAFs21dU3qeW+G5qROPX5zzta/IYln4Iy T2ajlzXVRSDlRIU5HkKXgVEzEI7HVByWHwttldhPJ7L023dlkwUhBk6ij9GwZ7UKv70x jVNA== X-Forwarded-Encrypted: i=1; AJvYcCWrvrvwNQ3fhkMzcnSwUIBxMHnutdb/L2IqjW91XcbB3r2VsnBxqXB7hcuGXfqToHKpn50By0fc0NTX@lists.postgresql.org X-Gm-Message-State: AOJu0YxHCJqyEHSiqiGF2TuOZjxNribLHaowILSr312YaDei7D9AKYt7 EuEDeIuOB/yhHKDaw/noOAcFXiaf/F7x4NEq+wT8KogZaHBrc1dnu//6bjo0RswufE2LDqbXkSr yxdKB6N4KLg== X-Gm-Gg: ASbGncsBGIaFAWhuAGd9lcaDm6xUltJGSg9YrHHL7MhRMpc9HVVfqcX+8YmbBHerECD H/rJFEvoWVRz2iuZCcyVBVjtWdqlQQVLu6/s+F2eG7ul18AlHlWfaMzPz/QyU2ZysS+6emYvWFo 6oK+GyyDufbRzMNQWqKuYvl7fYPHC9pGOOOYfk1x6BU3oX2cD0od9rEeQtJxtxO/fyEa2Qh+P1Y mCWV/2bopaXBlicYMI6C6Sfnog/JSyxbb9u4fiEcs57LqWhLPN3g4UgZEebmyongPxPX9rFwMLG nmRsJL/x9lwnx11qIHSfHFzJVj1by+xOGnpjy+0s4Pxslhim3lx26UwI8oAg3HsB2GyBmRQ8p6R n1RaP45aRRngAoiEB1OYJ3Ze8ySG/eGbE54III8/OyzrF3bsPf5PYcf6BhwGTs6iENwBC33hj2b s8CPPno46s4We/hBD0o3SbreRyOvjvUZlW4XBJ0QkwhO69NdilI/o= X-Google-Smtp-Source: AGHT+IHG7MpPydYQkwczc/AaUJTlMzj0A9Br9CMm0amCJ1Vfr2xhxUpUlFn7ikOfUMT++mXZQ1b9mA== X-Received: by 2002:a17:907:7f19:b0:b76:31e6:2ee1 with SMTP id a640c23a62f3a-b76c53c1714mr3472987966b.18.1764692695238; Tue, 02 Dec 2025 08:24:55 -0800 (PST) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:70:4d50:82d5:e2a3:8d7d:8548]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f59a6a5csm1570032666b.41.2025.12.02.08.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 08:24:54 -0800 (PST) Message-ID: <60b467ac47d5c6bbb9c21c3bdfecce8e5de60cda.camel@cybertec.at> Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation From: Laurenz Albe To: adam.warland@infor.com, pgsql-bugs@lists.postgresql.org Date: Tue, 02 Dec 2025 17:24:54 +0100 In-Reply-To: <19341-1d9a22915edfec58@postgresql.org> References: <19341-1d9a22915edfec58@postgresql.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-12-02 at 10:03 +0000, PG Bug reporting form wrote: > PostgreSQL version: 18.1 >=20 > When using a nondeterministic ICU collation, the replace() function fails= to > replace a substring when that substring appears at the end of the input > string. >=20 > Occurrences of the same substring earlier in the string are replaced > normally. >=20 > Specific collation used: > create collation test_nondeterministic ( > provider =3D icu, > locale =3D 'und-u-ks-level2', > deterministic =3D false > ) >=20 > -- Replace final character under nondeterministic collation > SELECT replace( > 'testx' COLLATE "test_nondeterministic", > 'x' COLLATE "test_nondeterministic", > 'y') AS res1; I can reproduce the problem, and the attached patch fixes it for me. I am not certain if it is safe to apply pg_mblen() to "haystack_end", thoug= h. Yours, Laurenz Albe