Re: Regular expression to UPPER() a lower case string - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: Regular expression to UPPER() a lower case string
Date
Msg-id 20221210144858.vmaglmltkytgemu6@hjp.at
Whole thread Raw
In response to Re: Regular expression to UPPER() a lower case string  (Eagna <eagna@protonmail.com>)
Responses Re: Regular expression to UPPER() a lower case string  (Eagna <eagna@protonmail.com>)
Re: Regular expression to UPPER() a lower case string  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
List pgsql-general
On 2022-12-10 14:36:04 +0000, Eagna wrote:
> > I want to index on a REGEXP_REPLACE() - I thought using lower -> upper would be a good test.
>
> > I could always have used another REGEXP_REPLACE() for my testing,
> > but I then became "obsessed"  with the idea of using
> > REGEXP_REPLACE() as a substitute for UPPER() - kind of an obfuscated
> > code competition with myself! :-)
>
> ========================
>
> So, I have no actual *_need_* for this, other than a desire to learn
> and understand what's going on and why.

You can't do that. Well, theoretically you could replace every
individual lower case letter with it's upper case equivalent:

select regexp_replace(...regexp_replace(regexp_replace(s, 'a', 'A'), 'b', 'B')... 'z', 'Z') ...

but that would be insane even for the 26 letters of the basic Latin
alphabet, much less the myriad of accented letters (and other alphabets
like Cyrillic or Greek ...).

On second thought you could probably use NFD normalization to separate
base letters from accents, uppercase the base letters and then
(optionally) NFC normalize everything again. Still insane ;-).

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: Eagna
Date:
Subject: Re: Regular expression to UPPER() a lower case string
Next
From: Gianni Ceccarelli
Date:
Subject: Re: Regular expression to UPPER() a lower case string