Re: Fault with initcap - Mailing list pgsql-sql

From Steve Midgley
Subject Re: Fault with initcap
Date
Msg-id CAJexoSLdHQcMfdnNk5xhXDPpsANMV2oOFi+3neHv=fi7QhsW6Q@mail.gmail.com
Whole thread Raw
In response to Re: Fault with initcap  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-sql


On Tue, Oct 12, 2021 at 9:54 AM Rob Sargent <robjsargent@gmail.com> wrote:


> On Oct 12, 2021, at 10:30 AM, Shaozhong SHI <shishaozhong@gmail.com> wrote:
>
> I tried initcap and found a major problem with it.
>
> Initcap of notemachine is NoteMachine.
My version 12 system gives Notemachine
>
> Initcap of Sainsbury's Bank is Sainsbury'S bank.
>
> This is not expected.
>
> Anyway to get around this problem?
>


Pg v.13 doesn't have a problem with notemachine either, but does seem to screw up Sainsbury's Bank as Sainsbury'S bank.


The only way I could think of fixing this would be to swap out the apostrophe with an alpha string not present in the string, and then swap back when you're done (see example above -- I'm not recommending using "xyzxyz" - that's just an example. And ideally you'd search for your placeholder string first to be sure it doesn't exist, or escape it).

Or just use a regexp to solve your casing problem -- maybe break up your string by whitespace into array elements, uppercase the first letter of each array and the concat the array elements back?

Steve
 

pgsql-sql by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Fault with initcap
Next
From: JP
Date:
Subject: Re: Removing JSONB key across all elements of nested array