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 1vRgqk-002X0a-0u for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Dec 2025 01:12:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vRgqi-00AajK-39 for pgsql-bugs@arkaria.postgresql.org; Sat, 06 Dec 2025 01:12:37 +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 1vRgqi-00AaiU-2L for pgsql-bugs@lists.postgresql.org; Sat, 06 Dec 2025 01:12:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vRgqg-003ND4-2S for pgsql-bugs@lists.postgresql.org; Sat, 06 Dec 2025 01:12:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5B61CCv42074713; Fri, 5 Dec 2025 20:12:13 -0500 From: Tom Lane To: Laurenz Albe cc: Heikki Linnakangas , adam.warland@infor.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation In-reply-to: <792a0aeb486e240ea34f10f895e0368fc434b8b7.camel@cybertec.at> References: <19341-1d9a22915edfec58@postgresql.org> <60b467ac47d5c6bbb9c21c3bdfecce8e5de60cda.camel@cybertec.at> <6935ea1e-cfb1-400b-9057-3d43b55d621a@iki.fi> <9f47c6b24d6cf59002603caf19b8b3f4854176be.camel@cybertec.at> <375807.1764696352@sss.pgh.pa.us> <464a14fcbee9567ace136716714b8c18f9bd87fb.camel@cybertec.at> <436944.1764708826@sss.pgh.pa.us> <0bbe14779f2c37e5a2fbd514861ebedaf8f53df6.camel@cybertec.at> <640025.1764774727@sss.pgh.pa.us> <792a0aeb486e240ea34f10f895e0368fc434b8b7.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Thu, 04 Dec 2025 18:14:51 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2074711.1764983532.1@sss.pgh.pa.us> Date: Fri, 05 Dec 2025 20:12:12 -0500 Message-ID: <2074712.1764983532@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Wed, 2025-12-03 at 10:12 -0500, Tom Lane wrote: >> We do require callers to eliminate the empty-needle case, and given >> that I think we could assume that match substrings must be at least >> 1 byte long. That assumption is what justifies the current API for >> these functions, and perhaps we can also simplify this loop by >> using it. > The attached v5 patch simplifies the loop to a do-while loop, assuming > that we cannot find a zero-length match. > I have also updated the comments to no longer mention the possibility > of an empty match, and for good measure I have added an Assert() that > the needle cannot be empty. LGTM. Pushed with tiny cosmetic fixes (mostly, more work on the comments). regards, tom lane