pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: adam.warland@infor.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Date: Wed, 03 Dec 2025 10:12:07 -0500
Message-ID: <640025.1764774727@sss.pgh.pa.us> (raw)
In-Reply-To: <0bbe14779f2c37e5a2fbd514861ebedaf8f53df6.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>

Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Tue, 2025-12-02 at 15:53 -0500, Tom Lane wrote:
>> Looking at the code overall, I wonder if the outer loop doesn't have
>> the same issue.  The comments claim that we should be able to handle
>> zero-length matches, but if the overall haystack is of length zero,
>> we will fail to check for such a match.

> If you can find zero-length matches at all, you could find a
> zero-length match in a non-empty haystack.  Perhaps the function is
> never called with an empty haystack...

After further thought, it seems to me that this comment is an
unjustified extrapolation from what Peter actually said, which was
that the match substring could be physically shorter than the needle.
Which is certainly true, for instance case-folding or accent-stripping
might shorten the string.  But it doesn't follow that a nonempty
needle could ever match an empty substring; and that does not seem
like it could be sane behavior to me.  We're considering string
comparison here, not regexes.

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.

			regards, tom lane





view thread (16+ messages)  latest in thread

Message-ID: <640025.1764774727@sss.pgh.pa.us>
Permalink:  ../640025.1764774727@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/640025.1764774727@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, laurenz.albe@cybertec.at, hlinnaka@iki.fi, 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: <640025.1764774727@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox