Re: Simple method to format a string?

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: Bosco Rama <postgres(at)boscorama(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Simple method to format a string?
Date: 2012-06-20 20:16:35
Message-ID: 4FE22FA3.2030502@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> 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'\\& '

After combined with several more replace(s), regexp_replace will provide
me the expecting result.

Thanks!
Emi

--
select
regexp_replace(
replace(
replace(col-val, ' ', ''), '-', ''),
.... replace...
'(...)', E'\\1 ', 'g')
from tn;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2012-06-21 02:47:20 Re: 32-bit libpq with 64-bit server
Previous Message Merlin Moncure 2012-06-20 19:59:49 Re: RETURNING MORE THAN ONE CUSTOM TYPE FROM FUNCTION