Re: Fault with initcap

From: Steve Midgley <science(at)misuse(dot)org>
To: Rob Sargent <robjsargent(at)gmail(dot)com>
Cc: Shaozhong SHI <shishaozhong(at)gmail(dot)com>, pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Fault with initcap
Date: 2021-10-12 17:28:23
Message-ID: CAJexoSLdHQcMfdnNk5xhXDPpsANMV2oOFi+3neHv=fi7QhsW6Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Tue, Oct 12, 2021 at 9:54 AM Rob Sargent <robjsargent(at)gmail(dot)com> wrote:

>
>
> > On Oct 12, 2021, at 10:30 AM, Shaozhong SHI <shishaozhong(at)gmail(dot)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.

https://www.db-fiddle.com/f/m2BMATwVcp6A1ZvD8TyurW/1

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karsten Hilbert 2021-10-12 17:52:56 Aw: Re: Fault with initcap
Previous Message Rob Sargent 2021-10-12 16:53:59 Re: Fault with initcap

Browse pgsql-sql by date

  From Date Subject
Next Message Karsten Hilbert 2021-10-12 17:52:56 Aw: Re: Fault with initcap
Previous Message Rob Sargent 2021-10-12 16:53:59 Re: Fault with initcap