Re: Fault with initcap

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Fault with initcap
Date: 2021-10-13 00:27:51
Message-ID: 1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On 10/12/21 16:03, Shaozhong SHI wrote:
>
>

>
> Hi, Adrian Klaver,
>
> In Python, there is  a capwords.  Do we have an equivalent in Postgres?

https://docs.python.org/3/library/string.html?highlight=capwords#string.capwords

string.capwords(s, sep=None)

Split the argument into words using str.split(), capitalize each
word using str.capitalize(), and join the capitalized words using
str.join(). If the optional second argument sep is absent or None, runs
of whitespace characters are replaced by a single space and leading and
trailing whitespace are removed, otherwise sep is used to split and join
the words.

That is not going to do what you are proposing either as it still comes
down to deciding where to split the 'words':

import string

string.capwords('notemachine')

'Notemachine'

There are similar functions to split strings here:

https://www.postgresql.org/docs/14/functions-string.html

Though again they depend on some delimiter or regexp to make the split.

There is no function that just 'knows' that 'notemachine' is two words
and should become 'NoteMachine'.

> Regards, David

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lee Hachadoorian 2021-10-13 03:55:08 Re: Fault with initcap
Previous Message Shaozhong SHI 2021-10-12 23:03:07 Re: Fault with initcap

Browse pgsql-sql by date

  From Date Subject
Next Message Lee Hachadoorian 2021-10-13 03:55:08 Re: Fault with initcap
Previous Message Steve Midgley 2021-10-13 00:17:26 Re: Removing JSONB key across all elements of nested array