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;