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 1uRapw-00DpRK-Dp for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Jun 2025 18:15:08 +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 1uRaps-00C2m3-0Y for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Jun 2025 18:15:04 +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 1uRapr-00C2lu-NG for pgsql-hackers@lists.postgresql.org; Tue, 17 Jun 2025 18:15:04 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uRapq-002XFT-0U for pgsql-hackers@postgresql.org; Tue, 17 Jun 2025 18:15:02 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7481600130eso6660588b3a.3 for ; Tue, 17 Jun 2025 11:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1750184100; x=1750788900; 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=BUJjBnBhTuIQY5SxdTE1uRx6nvH7dVClO8gZTkttJMs=; b=nnplf+P2ypNDoC56k6MumCTV+Fq9zovQn7LSp/WVqjmQsRRk0eWjwF7TdFLPpwesfM /suRTiBCIqZChSs9qIdd7GLh1GIQmIPmXLMIB+HX/rl297diQB/yDfrBRU5h5CFLyk8r rGK6aVnwzNsRGXVD8bKOFafyskANlY+TUvsRle+P0V2yC2DIJ7IRaHj0BXJggbEL+lU5 BG/ehtyLs8slkWFcInmULXuqWfPHWIsZFPUc0jf/mKlgXdRNjsQX6/FJtNBWj+oUJ4OE 3lwXYNACw8rA+gbMfWhbZwlDwxmzrLAFR8o58vM2a1ZrX6MsfVHFpGRmOcYeVYO9r2OY Peqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750184100; x=1750788900; 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=BUJjBnBhTuIQY5SxdTE1uRx6nvH7dVClO8gZTkttJMs=; b=Ta8VnVbUvRO5bsAhwCoBAxiQr3szCyfhWJvgYqX1J+08BUNqw3nBoyM+lW3zCAMv8Y CDnmqKpw/vgbYVK6kktisRSzSeoiY1UXugHe7JqhfyyMg5oejyYdAHe4edcL8ySb2F9T f4GUL5SjLMq1FIsrMS6KjRIk97dkiOp6oC+lX6OkW0xzt3iBOOD9taSgSRrtvT1tMxGb io0hecAhTlo1wOYfMBBy+8HK3RPv41Ot3qfxj0twB0Mt+H1J/bVSU1G2HwVnMXOFDNxq et3QFxrZ+PQh8B4UE86Wy+JDUFLb3ZpD8xcoAnEwomGR3sR8IB/GRKxbAqYGCiEQZURK z8VA== X-Gm-Message-State: AOJu0Yw3qLy1pPUb1gRGCcSlwrc1SXTxTYOsnWQB7P3Awvz0XLCL0uPh OneAel3Af00lK0AzlP0HwsJRx/h6Wpk+BXRmqqqchez4yvI6xKwLJrP3UdxxfrZAOQ== X-Gm-Gg: ASbGncuHtA7x9oVVqc7WpPrFEGgB/6xD1HVeint4ipdPXchxxrjYRKnd44iyQUb7pGr qeklrnwtpXqH46SXVhfLDPQl3Z1dKz1Ryi4UMsBag0/YYCeUNR6/9ei/TXcxOXLRQRifncubzxC dJH/RMeMdyVvi/OcAYZtxzhlxBvJrkVPp0JyBJbeor0DaVu+Z6FKybVDZl3gAQRH2jnOJUJ1hXQ SPTGgTJjKIUfTnvUUob8WoM+Bi8jTM5jjl11O5bHC3+AXLCBgCu7+Y5x7nGj63L6xGcMxlez2EH F/mi88ZezEz/MZ154KUVfbpYbh/sOFsmu0QLt9VYrZfE3n8qrfcDM6/F3iU4qQ== X-Google-Smtp-Source: AGHT+IFItKhPNilqXopDezTKhuBjSG5lAIBcDF4pYUDOancJIs8uDhwNnJdMX9MVk5Xt2g0UZ8B51A== X-Received: by 2002:a05:6a00:2e8f:b0:740:a879:4f7b with SMTP id d2e1a72fcca58-7489d174486mr18727053b3a.18.1750184100249; Tue, 17 Jun 2025 11:15:00 -0700 (PDT) Received: from [172.18.4.26] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-748900ac001sm9424556b3a.108.2025.06.17.11.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 11:14:59 -0700 (PDT) Message-ID: Subject: Re: Add CASEFOLD() function. From: Jeff Davis To: Vik Fearing , Joe Conway , Ian Lawrence Barwick Cc: pgsql-hackers@postgresql.org, Peter Eisentraut Date: Tue, 17 Jun 2025 11:14:58 -0700 In-Reply-To: <36f69fa9-db3f-44a1-8c8a-95ff09704a9c@postgresfriends.org> References: <47716a78-eb0b-4728-8991-fc0d958a01c9@joeconway.com> <36f69fa9-db3f-44a1-8c8a-95ff09704a9c@postgresfriends.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 2025-06-17 at 17:37 +0200, Vik Fearing wrote: > If the character set of is UTF8, UTF16, or UTF32, > then FR is replaced by > =C2=A0=C2=A0=C2=A0=C2=A0 Case: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 i) If the S IS NORMALIZED evaluates to > True, then NORMALIZE (FR) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ii) Otherwise, FR. I read that as "if the input is normalized, then the output should be normalized", IOW preserve the normalization. But does it mean "preserve whatever the input normal form is" or "preserve NFC if the input is NFC, otherwise the normalization is undefined"? The above wording seems to mean "preserve NFC if the input is NFC", because that's what NORMALIZE(FR) does when the normal form is unspecified. > It does not appear to me that our LOWER and UPPER functions obey this > rule, You are correct: WITH s(t) AS (SELECT NORMALIZE(U&'\00C1\00DF\0301' COLLATE "en-US-x-icu")) SELECT UPPER(t) =3D NORMALIZE(UPPER(t)) FROM s; ?column?=20 ---------- f > so there is a valid argument that we should continue to ignore it. > Or, we can say that we have at least one of three compliant. What do other databases do? Given how costly normalization can be, imposing that on every caller seems like a bit much. And favoring NFC for the user unconditionally might not be the best thing. Then again, NFC is good most of the time, and there are patches to speed up normalization. I tend to think that a lot of users who want casefolding would also want normalization, but it's hard to weigh that against the performance cost. It might not matter outside of a few edge cases, though I'm not sure exactly how many. Regards, Jeff Davis