Re: Simple method to format a string? - Mailing list pgsql-general

From Bosco Rama
Subject Re: Simple method to format a string?
Date
Msg-id 4FE220D1.7070409@boscorama.com
Whole thread Raw
In response to Simple method to format a string?  (Emi Lu <emilu@encs.concordia.ca>)
Responses Re: Simple method to format a string?
List pgsql-general
Emi Lu wrote:
> Good morning,
>
> Is there a simply method in psql to format a string?
>
> For example, adding a space to every three consecutive letters:
>
> abcdefgh -> *** *** ***

Depending on how you want 'extras' handled, you could work from
something like this:

   select trim(regexp_replace('123456', '...', '\& ', 'g'));

If you don't care about trailing space remove the 'trim()'.

The replacement string may need to be escaped differently depending
on your PG version and setting for standard_conforming_strings.  For
example:  E'\\& '

HTH

Bosco.

pgsql-general by date:

Previous
From: Edson Richter
Date:
Subject: Re: efficiency of wildcards at both ends
Next
From: Thomas Kellerer
Date:
Subject: Re: efficiency of wildcards at both ends