Re: Fault with initcap

From: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
To: Metin Ulusinan <metin(dot)ulusinan(at)ssicilian(dot)net>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Fault with initcap
Date: 2021-11-30 00:17:54
Message-ID: CA+i5JwbB5PFnxnoSiysRPE5ZJpDkUMSCrquFh-Ot296cy12+2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

It is better to reveal the content of initcap.

But, \sf+ initcap and etc. did not reveal.

Regards,

David

On Thu, 14 Oct 2021 at 14:42, Metin Ulusinan <metin(dot)ulusinan(at)ssicilian(dot)net>
wrote:

> Problem is about with parantesheses in text
> and real problem is non alphanumeric chars.
> Different samples will cause different problems.
> We don't know about your data and samples.
>
> But i changed the code again from original one.
> I deleted " ' " char in regexp function code.
> It seems better than before.
>
>
>
> CREATE OR REPLACE FUNCTION public.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'[\\[\\]\^\$\.\|\?\*\+\(\)\\~`\!(at)#%&\\-\\_+={}"<>:;, ]');
> FOREACH word IN ARRAY word_array
> LOOP
> word_out := upper(left(word, 1)) || lower(substring(word, 2));
> sentence := replace(sentence, word, word_out);
> END LOOP;
>
> RETURN trim(sentence);
> END;
> $function$
> ;
>
>
> On Thu, Oct 14, 2021 at 11:55 AM Shaozhong SHI <shishaozhong(at)gmail(dot)com>
> wrote:
>
>>
>>
>> On Wed, 13 Oct 2021 at 10:39, Metin Ulusinan <
>> metin(dot)ulusinan(at)ssicilian(dot)net> wrote:
>>
>>> 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$
>>> ;
>>>
>>> Hello, Metin,
>>>
>>
>> See the following testing response.
>>
>> ERROR: invalid regular expression: parentheses () not balanced CONTEXT:
>> PL/pgSQL function testinitcap2(text) line 18 at assignment
>> SQL state: 2201B
>>
>> Regards,
>>
>> David
>>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2021-11-30 01:14:55 Re: split postgresql logfile
Previous Message James Sewell 2021-11-29 23:45:59 Re: Max connections reached without max connections reached

Browse pgsql-sql by date

  From Date Subject
Next Message James Kitambara 2021-12-09 10:36:34 ERROR ON INSERTING USING A CURSOR IN EDB POSTGRESQL
Previous Message aditya desai 2021-11-16 17:10:08 SELECT on view runs slower with more WHERE conditions