pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Jakub Jedelsky <jakub.jedelsky@gooddata.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: case insensitive collation of Greek's sigma
Date: Wed, 1 Dec 2021 20:29:33 +0100
Message-ID: <9e3220da-d47e-add7-8b97-7c65b12ff6d7@enterprisedb.com> (raw)
In-Reply-To: <CAC1JxDQhi_M4WO4e19qPmcOGpN6NKJz60zsdXMuCHwVuE3_Ldw@mail.gmail.com>
References: <CAC1JxDQhi_M4WO4e19qPmcOGpN6NKJz60zsdXMuCHwVuE3_Ldw@mail.gmail.com>

On 26.11.21 08:37, Jakub Jedelsky wrote:
> postgres=# SELECT
> postgres-# 'ΣΣ' ILIKE 'σσ' COLLATE "en_US",
> postgres-# 'ΣΣ' ILIKE 'σς' COLLATE "en_US"
> postgres-# ;
>   ?column? | ?column?
> ----------+----------
>   t        | f
> (1 row)
> 
> postgres=# SELECT
> postgres-# 'ΣΣ' ILIKE 'σσ' COLLATE "en-US-x-icu",
> postgres-# 'ΣΣ' ILIKE 'σς' COLLATE "en-US-x-icu";
>   ?column? | ?column?
> ----------+----------
>   f        | t
> (1 row)
> 
> If I could start, I think both results are wrong as both should return 
> True. If I got it right, in the background there is a lower() function 
> running to compare strings, which is not enough for such cases (until 
> the left side isn't taken as a standalone word).

The reason for these results is that for multibyte encodings, a ILIKE b 
basically does lower(a) LIKE lower(b), and

select lower('ΣΣ' COLLATE "en_US"), lower('ΣΣ' COLLATE "en-US-x-icu");
  lower | lower
-------+-------
  σσ    | σς

Running lower() like this is really the wrong thing to do.  We should be 
doing "case folding" instead, which normalizes these differences for the 
purpose of case-insensitive comparisons.





view thread (8+ messages)  latest in thread

Message-ID: <9e3220da-d47e-add7-8b97-7c65b12ff6d7@enterprisedb.com>
Permalink:  ../9e3220da-d47e-add7-8b97-7c65b12ff6d7@enterprisedb.com/
Also on:    postgresql.org/message-id/9e3220da-d47e-add7-8b97-7c65b12ff6d7@enterprisedb.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: peter.eisentraut@enterprisedb.com, jakub.jedelsky@gooddata.com
  Subject: Re: case insensitive collation of Greek's sigma
  In-Reply-To: <9e3220da-d47e-add7-8b97-7c65b12ff6d7@enterprisedb.com>
  References: <CAC1JxDQhi_M4WO4e19qPmcOGpN6NKJz60zsdXMuCHwVuE3_Ldw@mail.gmail.com> <9e3220da-d47e-add7-8b97-7c65b12ff6d7@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox