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 1tOKgX-005doL-6w for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Dec 2024 17:51:41 +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 1tOKgV-00FYA8-2U for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Dec 2024 17:51:38 +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 1tOKgU-00FY9z-Ju for pgsql-hackers@lists.postgresql.org; Thu, 19 Dec 2024 17:51:38 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tOKgR-000Pyx-If for pgsql-hackers@postgresql.org; Thu, 19 Dec 2024 17:51:37 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7fd51285746so639656a12.3 for ; Thu, 19 Dec 2024 09:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1734630694; x=1735235494; 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=XF/xBO+AK6FHvvnUAEHmWN9vFX8Czyc120yZQ8PrkTY=; b=bYH8+LTGoUGy/ffDedgvNxkvaCY4a++wLB78nwmQy0QCHtp6KY4vSS/0dOdZJLofKY A6fh7SrV3zjL1dNqmHo9w5IzXAoztiDwfzkv/08vqrcMPJuvMIXRoZOpZ7FDGO9cxooU 7R+Z2F0OV7QfnWmiA/MvFEyiFDODo+dXyZe/WLoS3ngY4NYn5oBueTZHMrrdTmEkFS+T 11gjxZlOLvbhr6mRFqOQyY1DLCWAp8zsgGxTmWp4WvwnuLWDOaauG9L6rud4Nb3fPZ8w f6Je3TeOMeYapB84yBOuA6tMIx38k++DdqYrbODjAHaBKPX2Spr30uqwJ6F3vmuKq54l x6gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734630694; x=1735235494; 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=XF/xBO+AK6FHvvnUAEHmWN9vFX8Czyc120yZQ8PrkTY=; b=dFvE3sEylJPRAmGWVEGU0D4quzJg83lIxMSaY94LC+hU8uvXJsnY1PPknaIxOObuYn 6I0OAu3NwlJAdUqjam7Ux+7E82aLJK4geqlDoAqWdQOIpIcKYXZo1q7PM4eq6+Mbahr7 hCrc7+k8se1Wg+EWn9qb0n5yNwXDI1TBWjlaAI7ChIV6dkrtJuLUv0vc2BY1f5t4hBQa 9ioqJn2TbWdjDM9KPBjiy7bCb0s5/aTy89DfEXa4Y5unlMMQzBo1ES+xX+rM+ma2aEU8 k+na9PnXjfZBysn/VzWa5CxN7yVyZLsIVmhrg4ZNXdQi//ZUa9CjqdkqrYYbHpWe2A+d XrNg== X-Gm-Message-State: AOJu0YwethYlJEKnvx/UwZRZSJ/NWT1+oxFktULlmvrQPvxW878RppPi TVNTq+ppLW5HWz9Cy6l+sK+bqIyvw57l1LZCVscaM8PayOrLhN0O0Z+q8vz5qHsshiZCWjKntoI = X-Gm-Gg: ASbGnctIPeOR88m0EAQX/Z2X/7wBMwdRF/bts7xuzDzuyCBcHJaOxImBzVe/0p7UQOk 4Np8ZcmAY1HALTL7RVLZ9eTsrx6R/WgE4l4DNU0+IlxO3I5JZIKLpCPgvrXoUH5gr3PF8vjkbZ5 ueiU1QG3r8CBXfwEI+/k98wfQMIe1Tb/UCIKitu/+cZwGZTi/c1Uu/jR4lqA4eIXqwNWuXSi9e6 NdSNJykb3BksaIwWVBGmHpxwTAlKactQGGsHeYK8/s/7ea3fNGxmsDzvSG4293aeF5sbrK7bw4o GktIyDqd37EyhJBiyiHSdYU= X-Google-Smtp-Source: AGHT+IGvBi87QIUN0yEyKLzJDm4djLzENVSkIqAW6nQrhVsmvBA6R9r1Dbre2Nq0RzFEbA08a0GjWQ== X-Received: by 2002:a05:6a20:d80b:b0:1e1:bf3d:a191 with SMTP id adf61e73a8af0-1e5dd5985fbmr492856637.33.1734630694585; Thu, 19 Dec 2024 09:51:34 -0800 (PST) Received: from jeff-laptop.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad831148sm1586986b3a.53.2024.12.19.09.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 09:51:33 -0800 (PST) Message-ID: <898752524b1ad658c5fdae789f823a0dc52e6171.camel@j-davis.com> Subject: Re: Add CASEFOLD() function. From: Jeff Davis To: Peter Eisentraut , Joe Conway , Ian Lawrence Barwick Cc: pgsql-hackers@postgresql.org Date: Thu, 19 Dec 2024 09:51:32 -0800 In-Reply-To: <8c384b0d-00f2-4515-8e60-ff7d0d4c093a@eisentraut.org> References: <47716a78-eb0b-4728-8991-fc0d958a01c9@joeconway.com> <8c384b0d-00f2-4515-8e60-ff7d0d4c093a@eisentraut.org> 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 17:18 +0100, Peter Eisentraut wrote: > Can you explain this in further detail?=C2=A0 I don't quite follow why > this=20 > would be required. I am unsure now. My initial reasoning was based on the idea that users would want to use CASEFOLD(t) in a unique expression index as an improvement over LOWER(t). And if you do that, you'd be surprised if some equivalent strings ended up in the index.=C2=A0I don't think that's a huge problem, because in other contexts we leave it up to the user to keep things normalized consistently, and a CHECK(t IS NFC NORMALIZED) is a good way to do that. 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. 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? We could tell users to use an expression index on NORMALIZE(CASEFOLD(t)) instead, but that feels like inefficient boilerplate. >=20 > Another might be that's not entirely clear how this should work in=20 > encodings other than UTF-8.=C2=A0 For example, the normalized string migh= t > not be representable in the encoding. That's a good point. Regards, Jeff Davis