agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Adrian Klaver <adrian.klaver@aklaver.com>
To: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Fault with initcap
Date: Tue, 12 Oct 2021 17:27:51 -0700
Message-ID: <1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com> (raw)
In-Reply-To: <CA+i5JwZ1K83K-TMsz7T=o2jQ+=2VcUKp-bh3VxH-j-HBjhSxpw@mail.gmail.com>
References: <CA+i5JwZNEkm_geK6wSfc03D-qCaccOsW+_O2Dcc0h1VOBQfz2Q@mail.gmail.com>
<CA+i5Jwb7gv4N9qfctixtJFEpEAdeb7yOU1zoZ-HsaQdwmbGEmg@mail.gmail.com>
<10fbeda1-606a-553b-3598-eca814f40bb7@aklaver.com>
<CA+i5JwYOMPrzNgX0eu6w+NFTObKf9NCiE3BKK2bS3nNd_=FfdA@mail.gmail.com>
<157d10c3-a683-3373-3550-06113149cc51@aklaver.com>
<CA+i5JwZ1K83K-TMsz7T=o2jQ+=2VcUKp-bh3VxH-j-HBjhSxpw@mail.gmail.com>
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
view thread (19+ messages) latest in thread
Message-ID: <1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com>
Permalink: ../1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com/
Also on: postgresql.org/message-id/1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: adrian.klaver@aklaver.com, shishaozhong@gmail.com, pgsql-general@lists.postgresql.org
Subject: Re: Fault with initcap
In-Reply-To: <1aad747a-4c6f-6afd-71e8-e18adbd29835@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox