Обсуждение: How to remove a set of characters in text-columns ?

Поиск
Список
Период
Сортировка

How to remove a set of characters in text-columns ?

От
Andreas
Дата:
Hi,
how can I remove a set of characters in text-columns ?
Say I'd like to remove { } ( ) ' " , ; . : !
Of course I can chain replace ( replace ( replace ( replace ( ... , '' ) 
.... and replace the chars one by one against an empty string ''.

There might be a more elegant way.
Is there ?


regards


Re: How to remove a set of characters in text-columns ?

От
Steve Crawford
Дата:
On 06/30/2011 12:28 PM, Andreas wrote:
> Hi,
> how can I remove a set of characters in text-columns ?
> Say I'd like to remove { } ( ) ' " , ; . : !
> Of course I can chain replace ( replace ( replace ( replace ( ... , '' 
> ) .... and replace the chars one by one against an empty string ''.
>
> There might be a more elegant way.
> Is there ?
>
>
> regards
>
Look at regexp_replace()
http://www.postgresql.org/docs/9.0/static/functions-string.html
http://www.postgresql.org/docs/9.0/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP

Cheers,
Steve



Re: How to remove a set of characters in text-columns ?

От
Tim Landscheidt
Дата:
(anonymous) wrote:

> how can I remove a set of characters in text-columns ?
> Say I'd like to remove { } ( ) ' " , ; . : !
> Of course I can chain replace ( replace ( replace ( replace
> ( ... , '' ) .... and replace the chars one by one against
> an empty string ''.

> There might be a more elegant way.
> Is there ?

Besides the regexp_replace() solution mentioned by Charlie
and Steve, you can also use TRANSLATE():

| tim=# SELECT TRANSLATE('a{b''c"d!f', '{}()''",;.:!', '');
|  translate
| -----------
|  abcdf
| (1 Zeile)

| tim=#

Tim



Re: How to remove a set of characters in text-columns ?

От
Andreas
Дата:
Am 01.07.2011 04:17, schrieb Tim Landscheidt:
> besides the regexp_replace() solution mentioned by Charlie
> and Steve, you can also use TRANSLATE():
>
> | tim=# SELECT TRANSLATE('a{b''c"d!f', '{}()''",;.:!', '');

nice, 2 solutions for 1 problem.   :)
my replace...replace... was a wee bit tedious   ;)

thanks a lot to you, Charlie and Steve   :)


regards
Andreas