agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Jain, Ankit <Ankit.Jain@snapon.com>
To: Metin Ulusinan <metin.ulusinan@ssicilian.net>
To: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: RE: Fault with initcap
Date: Wed, 13 Oct 2021 16:17:50 +0000
Message-ID: <92eda9197fd74bf9aa9cd41bad115ec6@snapon.com> (raw)
In-Reply-To: <CAPi93JRY5yQG6iA+bmx6KkVS-TK3zF6EHxR-oYuBhamoCa+jhA@mail.gmail.com>
References: <CA+i5JwZNEkm_geK6wSfc03D-qCaccOsW+_O2Dcc0h1VOBQfz2Q@mail.gmail.com>
	<CAPi93JTZh9L6EFxa_-Y8-7mY1XrmM2KxobHjvvBwUkbYOM3Gmw@mail.gmail.com>
	<CA+i5JwaGGpAZeoSfUXXCFbOGMy31YWV8wgEvGO9fX6+c2sHG7w@mail.gmail.com>
	<CAPi93JRY5yQG6iA+bmx6KkVS-TK3zF6EHxR-oYuBhamoCa+jhA@mail.gmail.com>

This was reported in PG 8.1.4 15 years ago - https://pgsql-bugs.postgresql.narkive.com/R7HmTKef/bug-2579-initcap-should-not-capitalize-letter-aft...

From: Metin Ulusinan <metin.ulusinan@ssicilian.net>
Sent: Wednesday, October 13, 2021 5:39 AM
To: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: Re: Fault with initcap


CAUTION: This email originated from outside of Snap-on. Do not click on links or open attachments unless you have validated the sender, even if it is a known contact. Contact the sender by phone to validate the contents.
Hi,
Yes, this can be adaptable, and i did simple version of this.
It just split text words with find spaces, capitalise each
pieces(word) and merge together again.
This is a quick and simple work. You can develop over it about your needs.

Try that and tell us about result.


CREATE OR REPLACE FUNCTION initcap2(text)
 RETURNS text
 LANGUAGE plpgsql
AS $function$
DECLARE
sentence TEXT := '';
word_array TEXT[];
word TEXT;
word_out TEXT;
BEGIN
sentence := $1;

IF sentence is NULL THEN
RETURN NULL;
END IF;

word_array := regexp_split_to_array($1, E'\\s+');
FOREACH word IN ARRAY word_array
LOOP
word_out := upper(left(word, 1)) || lower(substring(word, 2));
sentence := regexp_replace(sentence, word, word_out);
END LOOP;

RETURN trim(sentence);
END;
$function$
;



On Wed, Oct 13, 2021 at 11:48 AM Shaozhong SHI <shishaozhong@gmail.com<mailto:shishaozhong@gmail.com>> wrote:


On Wed, 13 Oct 2021 at 07:33, Metin Ulusinan <metin.ulusinan@ssicilian.net<mailto:metin.ulusinan@ssicilian.net>> wrote:
I tried both on PostgreSQL 11.13 and yes "Sainsbury's bank" 's "S" is buggy, but notemachine is not.

Will anyone try @ 14?


n

s

version

Notemachine

Sainsbury'S Bank

PostgreSQL 11.13 (Debian 11.13-0+deb10u1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit



Hello, Metin Ulusinan,

I can confirm that you pin-out the issue.

There is a INITCAP2.  Alternative function to PostgreSQL builtin initcap(text) with support for accented words. ยท GitHub<https://urldefense.com/v3/__https:/gist.github.com/pv8/8291531__;!!Lf_9VycLqA!yapR_3tOx6q4nbC3ZDtCTz...;

Can this be adapted to capitalise the first letter of each work in a string?

Regards,

David


view thread (19+ messages)  latest in thread

Message-ID: <92eda9197fd74bf9aa9cd41bad115ec6@snapon.com>
Permalink:  ../92eda9197fd74bf9aa9cd41bad115ec6@snapon.com/
Also on:    postgresql.org/message-id/92eda9197fd74bf9aa9cd41bad115ec6@snapon.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: Ankit.Jain@snapon.com, metin.ulusinan@ssicilian.net, shishaozhong@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: RE: Fault with initcap
  In-Reply-To: <92eda9197fd74bf9aa9cd41bad115ec6@snapon.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