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.94.2) (envelope-from ) id 1qo5cF-0007Ol-8e for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Oct 2023 17:24:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qo5bF-001gJw-5w for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Oct 2023 17:23:54 +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.94.2) (envelope-from ) id 1qo5bE-001gJj-Gx for pgsql-hackers@lists.postgresql.org; Wed, 04 Oct 2023 17:23:53 +0000 Received: from eastern.birch.relay.mailchannels.net ([23.83.209.55]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qo5b8-0000xO-C8 for pgsql-hackers@postgresql.org; Wed, 04 Oct 2023 17:23:52 +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 4C6AE4186C; Wed, 4 Oct 2023 17:23:44 +0000 (UTC) Received: from pdx1-sub0-mail-a226.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E2D534170F; Wed, 4 Oct 2023 17:23:43 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1696440223; a=rsa-sha256; cv=none; b=IU5TQfMVnk10SLxiTh/+0fFO7e+W4gmKhCqGenOEMymGSV6LML4y1i5hXgTJCTU1MsQrnM yW9KK8dHepykIDgVg0bnFOO8vx2m7Dj5JamLi1XdALyEmuspeV6uwy0q31wWJQiWO1moAJ xviypJi+USLWoNB8n5u0T5el5tp3XilTUywszjqyR0kLk/Bp1lxz+AQtCNbz27wH9dFlLZ zMcJ+xPTP2wY5M8l6Z+QSfQZbiW7Rk+TLjyp9/o1e8gLCv4G92vXbkVn93LCClRiMgNW5K 3h1kKLc2co4og/fTbeJw8S9DnNPoE38LkyVjApVVPJ3ggrO2ohGsM818Zibg6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1696440223; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rFuLxuoesNdVjovIqHzQzHBHUOZ4cChw3PffPaTd7T8=; b=4xXUQhnDeSqx8YhKZZVjJtH/Bh2vtT64p6Q4cfabtsF+NJJMokGgADcqQnZaeRj3Y3ZlMn lquYlXfEF94F6TeLmpnabDu6Db5lutQiDH4X/QtAo+SsBBgYa9L/JAjLCIxQeWWsgTf2lK tG8jHqLIF1l9j4ziUeJFhbSuna/ALKlqFMKEW1y/o6ApqkDA3E7YpGMLuMyJFhYp1XZbSr iVSWajFVLaNFU60YqY0vPNsGm9yWoaxQ0k52FBugplm/3ku9LNsYPe/n6hEV5hX41KFuLz uQDTGzukYtprBMdS1eOietluu9PJGnxscpX38PduZnXKag332/kMwUMPAfv7xQ== ARC-Authentication-Results: i=1; rspamd-7d5dc8fd68-s2jbf; 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-Whimsical-Daffy: 61bdffa965616763_1696440224150_3034440161 X-MC-Loop-Signature: 1696440224150:3049934320 X-MC-Ingress-Time: 1696440224150 Received: from pdx1-sub0-mail-a226.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.106.112.200 (trex/6.9.1); Wed, 04 Oct 2023 17:23:44 +0000 Received: from ubby21 (075-081-095-064.res.spectrum.com [75.81.95.64]) (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-a226.dreamhost.com (Postfix) with ESMTPSA id 4S11kR33g7zHn; Wed, 4 Oct 2023 10:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cryptonector.com; s=dreamhost; t=1696440223; bh=rFuLxuoesNdVjovIqHzQzHBHUOZ4cChw3PffPaTd7T8=; h=Date:From:To:Cc:Subject:Content-Type; b=Cnv8pY85c8o4GiI0AsFz9kvgGcW9USqHuuNIsTae/IXEEYnP5jZODzAnSXz/vq8gO FG+bYQnKPeaxNlI1hlHrrox9zaimGHeF5rR9/u1Uq7TjEhV4iYAaKly3Nl8rXzGO/+ iOJpWcxbHGXkea4RKaikkF1egK+UYYaA4lJTP0+S4ivk6hY8FJsAi2esLaQS6XY0zb crO4OgiFXi1Nqdj6FPqEIyf+DipG5TiUSb3DCKBI8hqfC2Ko+huX5JApX5ZBEMmuox 6Bj438xOFLOpTyItMx3zeNv4zrUmtRg//tEaZ4jsczoPm702HdYZgLodbhabomIAdr XeBjBLBg3Gkhg== Date: Wed, 4 Oct 2023 12:23:41 -0500 From: Nico Williams To: Jeff Davis Cc: pgsql-hackers@postgresql.org Subject: Re: Pre-proposal: unicode normalized text Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Sep 12, 2023 at 03:47:10PM -0700, Jeff Davis wrote: > The idea is to have a new data type, say "UTEXT", that normalizes the > input so that it can have an improved notion of equality while still > using memcmp(). A UTEXT type would be helpful for specifying that the text must be Unicode (in which transform?) even if the character data encoding for the database is not UTF-8. Maybe UTF8 might be a better name for the new type, since it would denote the transform (and would allow for UTF16 and UTF32 some day, though it's doubtful those would ever happen). But it's one thing to specify Unicode (and transform) in the type and another to specify an NF to normalize to on insert or on lookup. How about new column constraint keywords, such as NORMALIZE (meaning normalize on insert) and NORMALIZED (meaning reject non-canonical form text), with an optional parenthetical by which to specify a non-default form? (These would apply to TEXT as well when the default encoding for the DB is UTF-8.) One could then ALTER TABLE to add this to existing tables. This would also make it easier to add a form-preserving/form-insensitive mode later if it turns out to be useful or necessary, maybe making it the default for Unicode text in new tables. > Questions: > > * Would this be useful enough to justify a new data type? Would it be > confusing about when to choose one versus the other? Yes. See above. I think I'd rather have it be called UTF8, and the normalization properties of it to be specified as column constraints. > * Would cross-type comparisons between TEXT and UTEXT become a major > problem that would reduce the utility? Maybe when the database's encoding is UTF_8 then UTEXT (or UTF8) can be an alias of TEXT. > * Should "some_utext_value = some_text_value" coerce the LHS to TEXT > or the RHS to UTEXT? Ooh, this is nice! If the TEXT is _not_ UTF-8 then it could be converted to UTF-8. So I think which is RHS and which is LHS doesn't matter -- it's which is UTF-8, and if both are then the only thing left to do is normalize, and for that I'd take the LHS' form if the LHS is UTF-8, else the RHS'. Nico --