Re: Fault with initcap - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Fault with initcap
Date
Msg-id 1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com
Whole thread Raw
In response to Re: Fault with initcap  (Shaozhong SHI <shishaozhong@gmail.com>)
Responses Re: Fault with initcap
List pgsql-general
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.klaver@aklaver.com



pgsql-general by date:

Previous
From: Shaozhong SHI
Date:
Subject: Re: Fault with initcap
Next
From: Lee Hachadoorian
Date:
Subject: Re: Fault with initcap