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 1tVfLI-00AQDC-OP for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jan 2025 23:20:05 +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 1tVfLI-008Vt7-0I for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jan 2025 23:20:03 +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 1tVfLH-008Vsp-J9 for pgsql-hackers@lists.postgresql.org; Wed, 08 Jan 2025 23:20:03 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tVfLE-000bSk-2E for pgsql-hackers@postgresql.org; Wed, 08 Jan 2025 23:20:02 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-21675fd60feso5557475ad.2 for ; Wed, 08 Jan 2025 15:20:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1736378400; x=1736983200; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=DRUu2uv7UAkmo+djrvpijIUk965AoDdwuyastDIa4l0=; b=GgGNmZFiZPR8KiWzyYJrsuGO7ggVmSDeM5cjJ2uaKwZ0nOTc9Dr3ujIJW/USXvc57o p/UXpKBLDtYeFbekkEzyvV2l40esE7Q5sthT2MiTVlhShcXAlqDzVEA/qBZaJckt2xoj ekTlRk+cKJi6n9Z59zCzgGF3mNFOgXEOoeDx7VuzTqOz60z5xQUl4e3FPtD+AyK7RSpY 4fjsEU8NsM9QEk34Rhlgeshtikjec3s0gGiJj3syCQY4Cc211tDo1ayY4Uv6FzW8vOox BVNPSL61bHaLZEnI5Io9kIkt0sP69nrjT5HO1z3pX3h5SOkekF0kkbYxBj/BoZeaqdqN 9KtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736378400; x=1736983200; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DRUu2uv7UAkmo+djrvpijIUk965AoDdwuyastDIa4l0=; b=HJp6/RlRutWgsvTgcA6dHPX6ybvAMdXC8mfhro5J9aSEhrHcTuHyEBM6AtDiZRXUa8 PWfCFkGCihYUnk4Z6i3cGtCXRBrwjaQc2tXCfSKcxGm4AAEq84RNUpt6ExKIsgNhJgzd k0acl+FqXinjpDVBTG8gwgyMSG+mnfT6EJlWG3rEfwMeTcByrpvkR7s5jHYgBvdzxZXG 11zeeUqrmwJG6OES7HFvbsjc7hK81jR5Mdy0060tyWZphbTcUYjX2MWTokAjXCir80r8 9l/6I+4OUV0+cizrjuvnjDzW2fP2NYQYQh0WfTxa3HKjmYxICphmFE2jtTa6JPT3ItV+ 0rEQ== X-Gm-Message-State: AOJu0YzDLTznxu/NTLjoMg8HvmyJBeRLJoPo6B8ROTpe6bgRaLAzcWOq M4+fPx9u+pdfUh5pGqI6mKCwLCmgte/mGlwuERQjy3Qqi5R+12zkJ07RrRrqY6W/J2aRN2x317I = X-Gm-Gg: ASbGncvXrMl58FQO1kHdQrGED2PoN1KpkjMXxK5mS+I2VLWA5D9ae9AfE3f5hfBFgNw OTxU96FiwzrDI1R+SUpkyyChuzb4xx6romTNpQ02vRCIradIhURd0rSD8GGxC3ifmZt7YGEUHw4 D1imJjx0iEJdza9lY3D6moL9fB5ti3E4j70c+EWpjOnDfMFSQshWpWA2xd3xBjxzcwlYoFHIbv5 5JEuW1BJofUNfNO23wA/EANjuAAB/aITfhsy1zFPIz3iYb8CJG9EiOp X-Google-Smtp-Source: AGHT+IGH0kOF+KDDXpPNBtaoBGfgM9keNgJ/ZQji5YXryWT1/MP1I0/96QeR3IUGQCPHed2PGfYEZQ== X-Received: by 2002:a05:6a00:4386:b0:726:8366:40ca with SMTP id d2e1a72fcca58-72d21f1ab6amr6478897b3a.1.1736378399857; Wed, 08 Jan 2025 15:19:59 -0800 (PST) Received: from [172.24.2.43] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fe5fbsm36946486b3a.142.2025.01.08.15.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 15:19:59 -0800 (PST) Message-ID: Subject: Re: Add CASEFOLD() function. From: Jeff Davis To: Peter Eisentraut , Joe Conway , Ian Lawrence Barwick Cc: pgsql-hackers@postgresql.org Date: Wed, 08 Jan 2025 15:19:58 -0800 In-Reply-To: <898752524b1ad658c5fdae789f823a0dc52e6171.camel@j-davis.com> References: <47716a78-eb0b-4728-8991-fc0d958a01c9@joeconway.com> <8c384b0d-00f2-4515-8e60-ff7d0d4c093a@eisentraut.org> <898752524b1ad658c5fdae789f823a0dc52e6171.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2024-12-19 at 09:51 -0800, Jeff Davis wrote: > But there's a problem: full case folding doesn't preserve the normal > form, so even if the input is NFC normalized, the output might not > be. > If we solve this problem, then we can just say that CASEFOLD() > preserves the normal form, consistently with how the spec defines > LOWER()/UPPER(), and I think that would be the best outcome. >=20 > I'm not sure if that problem is solvable, though, because what if the > input string is in both NFC and NFD, how do we know which normal form > to preserve? The options as I see it are: 1. Normalize the output (either by using an extra parameter or just always normalizing to NFC). As you said, the problem here is that the encoding might not work with normalization. One solution might be that CASEFOLD() only works in UTF8, like NORMALIZE(). 2. Try to preserve normalization as long as the encoding supports it. The problem here is that we don't know what normal form to preserve, because the input string might be in both NFC and NFD. We could document that it preserves NFC form iff the input is NFC. 3. Allow CASEFOLD() to break the normal form of the input string. The problem here is that the user may be surprised that the output is not normalized even when all of their data is normalized. It's not clear to me whether it still works for caseless matching -- it might if the string is in a consistent form, even if not normalized. Out of those I think #1 is the most appealing. Most users, and especially users that care about these edge cases enough to use Full Case Folding, are almost certainly going to be on UTF8 anyway. It's also the most user-friendly. Regards, Jeff Davis