Re: Simple method to format a string?

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Cc: emilu(at)encs(dot)concordia(dot)ca
Subject: Re: Simple method to format a string?
Date: 2012-06-20 19:13:21
Message-ID: 4FE220D1.7070409@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2012-06-20 19:29:28 Re: efficiency of wildcards at both ends
Previous Message Edson Richter 2012-06-20 18:11:16 Re: efficiency of wildcards at both ends