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 1wOwNr-000IbU-09 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 May 2026 11:43:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wOwNo-001zYy-32 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 May 2026 11:43:41 +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 1wOwNo-001zYq-1S for pgsql-hackers@lists.postgresql.org; Mon, 18 May 2026 11:43:41 +0000 Received: from rusty.tulip.relay.mailchannels.net ([23.83.218.252]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wOwNm-00000000BAl-1DJA for pgsql-hackers@postgresql.org; Mon, 18 May 2026 11:43:40 +0000 X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id DE011940AFD; Mon, 18 May 2026 11:43:35 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (trex-green-1.trex.outbound.svc.cluster.local [100.109.22.205]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 8C493941FCE; Mon, 18 May 2026 11:43:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; d=mailchannels.net; s=arc-2022; cv=none; t=1779104615; b=27VqM/3LV3uQzx4OFj5i8HNtyJZxpvOpIUUzKizbsNibgqK6tcuZtA0SwE2Nbt4WPj7GiX VvZPmi2tMylRBbHM7oYD/bJjzn7s8zgkyabKzqlwMJiuKCnb6jBR1dHgZ+XDcAaGs1MUXR Mo1kM+KykQYLBHOyKy0XoYDAyBnJKA4XIvEGkKBEpnpiyJkirRbPfppHgu38nsLL2nf7xK JwKRJQEwvUcQflGA2xni27takwGHd2Gfu7t0FcUZwXM/tPgqv71paXHuPdVmCtmveuKgB+ mEcAbD8dYYXv8ED6aWuuV/G0jFt51V0M9QY7T2B2BzpZU3T0NMOeBfupxknW1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1779104615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9r1BaGZK/KEek8MmKjmd83a0je/vLo8ORIf1peYMF9o=; b=jOHdDL6fvgt1tpgtvaJhFhluj8P7r6Ze1DKM3wW4J885Au2XRc189QVwJQkPbRog8IyPyD /c5hDoZjGyyYAih1ncb6a2PbLJOhBlcsiNbIHI98GgNt+9Zdr5urTdbpKeAjDddXUhoU0V ihJoVmEa5l6NPs0899+yR8qIKwEJ/zr29xYWn6DwCE29Urno4oLTg5nZLDpeYGT/u29psQ ZJGpB6+OhTlDg2QxE9BT/fXvgV+lRqpu9be3P4USk+FWtjfqnVlZ2isgiLOhngr9/tgPk5 B2oX639LYWexrCt2KP7anQCSP8HqIJlhWo0kBb3Al02r19UUWlSavnoIF7ON9g== ARC-Authentication-Results: i=1; rspamd-54674b4cbd-686q6; auth=pass smtp.auth=dreamhost smtp.mailfrom=nico@cryptonector.com X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com X-MailChannels-Auth-Id: dreamhost X-Wipe-Vacuous: 1bf57efb547bfea8_1779104615805_1679276072 X-MC-Loop-Signature: 1779104615805:2593526078 X-MC-Ingress-Time: 1779104615805 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.22.205 (trex/7.1.5); Mon, 18 May 2026 11:43:35 +0000 Received: from ubby (unknown [24.28.102.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4gJwtG6LxjzyrH; Mon, 18 May 2026 04:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cryptonector.com; s=dreamhost; t=1779104615; bh=9r1BaGZK/KEek8MmKjmd83a0je/vLo8ORIf1peYMF9o=; h=Date:From:To:Cc:Subject:Content-Type:Content-Transfer-Encoding; b=O2AcZD67/p9ZOEAMR0KilEwYSU9bPseJyrvbPcxeItg+M+PbMYNV8P4YAxbqD/WhS 83ADxD7bVtNHQaguRsJq+8y7yrhKCPN8jfQHz+LeBxHgjozIPmUKCQuzOzHecFToS5 1TMAZatqSAClv+LYhMQg5OCwTg/XAdAGz9fd6zaEbzsII9vRYthkU16bn61Om5qJux UcmlFVpDksZbraUDGio2KBv2OdXwTuijI9Bf7C9IVSLmy/hUNmmjwMP0qqxctRZMZl 07gMJXqd3JcILWsA6JwEDF86e0yF/34noK2YTPPmXwRKJPi7uGIKvOvkxzerKQW6SI u9/pV1K5+5vig== Date: Mon, 18 May 2026 06:43:32 -0500 From: Nico Williams To: Peter Eisentraut Cc: Daniel Verite , Robert Haas , Pgsql-Hackers Subject: Re: Support LIKE with nondeterministic collations Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, May 03, 2024 at 08:58:30PM +0200, Peter Eisentraut wrote: > On 03.05.24 17:47, Daniel Verite wrote: > > Peter Eisentraut wrote: > > > > > However, off the top of my head, this definition has three flaws: (1) > > > It would make the single-character wildcard effectively an > > > any-number-of-characters wildcard, but only in some circumstances, which > > > could be confusing, (2) it would be difficult to compute, because you'd > > > have to check equality against all possible single-character strings, > > > and (3) it is not what the SQL standard says. > > > > For #1 we're currently using the definition of a "character" as > > being any single point of code, > > That is the definition that is used throughout SQL and PostgreSQL. We can't > change that without redefining everything. To pick just one example, the > various trim function also behave in seemingly inconsistent ways when you > apply then to strings in different normalization forms. The better fix there > is to enforce the normalization form somehow. That's unfortunate, because in Unicode a character (see below) need not be represented as a single code point, or even be possible to represent using a single code point -- multiple codepoints can be required even in order to represent a character. This means that substring operations need to exist that respect character boundaries rather than code point boundaries. Changing functions like `overlay()`, `position()` and `substring()` to count characters rather than codepoints would be a potentially breaking change. Or maybe a 'fixing change', depending on how one looks at it! But changing LIKE to respect character boundaries, especially in cases where LIKE would not have worked to begin with before this change, seems safe to me -- certainly it seems desirable. The example Daniel posted definitely shows how interpreting 'character' to mean 'code point' yields broken behaviors as seen by _humans_[0]. [0] And also by LLMs, though since those are [mainly / for now] trained on human-generated corpuses, these are human-like too! > > Intuitively I think that our interpretation of "character" here should > > be whatever sequence of code points are between character > > boundaries [1], and that the equality of such characters would be the > > equality of their sequences of code points, with the string equality > > check of the collation, whatever the length of these sequences. > > > [1]: > > https://unicode-org.github.io/icu/userguide/boundaryanalysis/#character-boundary > > Even that page says, what we are calling character here is really called a > grapheme cluster. Not quite. https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries | A single Unicode code point is often, but not always the same as a | basic unit of a writing system for a language, or what a typical user | might think of as a “character”. There are many cases where such a basic | unit is made up of multiple Unicode code points. To avoid ambiguity with | the term character as defined for encoding purposes, it can be useful to | speak of a user-perceived character. For example, “G” + grave-accent is | a user-perceived character: users think of it as a single character, yet | is actually represented by two Unicode code points. Here the spec refers to "user-perceived character", and leaves 'character' rather ill-defined, but then: https://www.unicode.org/glossary/ The Unicode glossary says: | Code Point. (1) Any value in the Unicode codespace; that is, the range | of integers from 0 to 10FFFF16. (See definition D10 in Section 3.4, | Characters and Encoding.) Not all code points are assigned to encoded | characters. See code point type. (2) A value, or position, for a | character, in any coded character set. | Character. (1) The smallest component of written language that has | semantic value; refers to the abstract meaning and/or shape, rather than | a specific shape (see also glyph), though in code tables some form of | visual representation is essential for the reader’s understanding. (2) | Synonym for abstract character. (3) The basic unit of encoding for the | Unicode character encoding. (4) The English name for the ideographic | written elements of Chinese origin. [See ideograph (2).] Note that a combining mark code point is _not_ a character by this definition (1), though (2): | Abstract Character. A unit of information used for the organization, | control, or representation of textual data. (See definition D7 in | Section 3.4, Characters and Encoding.) So control characters are also characters. Makes sense: newline and carriage return are meaningful to users of Latin scripts. For characters other than 'control' ones this does make it clear that a character is the coded representation of what we see as a 'glyph'. | Glyph. (1) An abstract form that represents one or more glyph images. | (2) A synonym for glyph image. In displaying Unicode character data, one | or more glyphs may be selected to depict a particular character. These | glyphs are selected by a rendering engine during composition and layout | processing. (See also character.) | | Grapheme. (1) A minimally distinctive unit of writing in the context of | a particular writing system. For example, ‹b› and ‹d› are distinct | graphemes in English writing systems because there exist distinct words | like big and dig. Conversely, a lowercase italiform letter a and a | lowercase Roman letter a are not distinct graphemes because no word is | distinguished on the basis of these two different forms. (2) What a user | thinks of as a character. | | Grapheme Cluster. The text between grapheme cluster boundaries as | specified by Unicode Standard Annex #29, "Unicode Text Segmentation." | (See definition D60 in Section 3.6, Combination.) A grapheme cluster | represents a horizontally segmentable unit of text, consisting of some | grapheme base (which may consist of a Korean syllable) together with any | number of nonspacing marks applied to it. > In a different world, pattern matching, character trimming, etc. would work > by grapheme, but it does not. In this very particular case it should though, and it wouldn't be a breaking change because: - LIKE with non-deterministic collations is not yet supported, so you wouldn't be changing any existing behaviors in a breaking manner - there is no PG function for partitioning a string into substrings using LIKE patterns (regular expressions, yes) (I think!) One could argue that counting graphemes rather than code points can only _fix_ bugs rather than break code, and I want to make that argument, but it's a harder argument to make, so I won't make it today. Nico --