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-10-14 08:55:14
Message-ID: CA+i5JwYeE4cKg7baz1UP9vUXX+n6UWOw98DLgVRDuB_szpN45w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message celati Laurent 2021-10-14 09:12:44 Postresql/postgis/qgis : assign privileges only for access/reading tables ?
Previous Message 张进涛 2021-10-14 06:21:25 ask for help:I want to compile a dynamic library file, such as libpsqlodbc w.so

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2021-10-14 10:31:18 What is the regex for apostraphe in postgres?
Previous Message Jain, Ankit 2021-10-13 16:17:50 RE: Fault with initcap