pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to remove a set of characters in text-columns ?
5+ messages / 4 participants
[nested] [flat]

* How to remove a set of characters in text-columns ?
@ 2011-06-30 19:28  Andreas <maps.on@gmx.net>
  0 siblings, 2 replies; 5+ messages in thread

From: Andreas @ 2011-06-30 19:28 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to remove a set of characters in text-columns ?
@ 2011-06-30 19:49  Steve Crawford <scrawford@pinpointresearch.com>
  parent: Andreas <maps.on@gmx.net>
  1 sibling, 0 replies; 5+ messages in thread

From: Steve Crawford @ 2011-06-30 19:49 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

*  Re: [SQL] How to remove a set of characters in text-columns ?
@ 2011-06-30 19:57  Charlie <scorpdaddy@hotmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Charlie @ 2011-06-30 19:57 UTC (permalink / raw)
  To: Andreas <maps.on@gmx.net>; pgsql-sql

Would 

regexp_replace(src_str, '[\{\}\[\]\(\)\.', '')

at

http://www.postgresql.org/docs/9.0/static/functions-string.html

help?




----- Reply message -----
From: "Andreas" <maps.on@gmx.net>
Date: Thu, Jun 30, 2011 4:28 pm
Subject: [SQL] How to remove a set of characters in text-columns ?
To: <pgsql-sql@postgresql.org>

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

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to remove a set of characters in text-columns ?
@ 2011-07-01 02:17  Tim Landscheidt <tim@tim-landscheidt.de>
  parent: Andreas <maps.on@gmx.net>
  1 sibling, 1 reply; 5+ messages in thread

From: Tim Landscheidt @ 2011-07-01 02:17 UTC (permalink / raw)
  To: pgsql-sql

(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




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: How to remove a set of characters in text-columns ?
@ 2011-07-01 02:43  Andreas <maps.on@gmx.net>
  parent: Tim Landscheidt <tim@tim-landscheidt.de>
  0 siblings, 0 replies; 5+ messages in thread

From: Andreas @ 2011-07-01 02:43 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2011-07-01 02:43 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-30 19:28 How to remove a set of characters in text-columns ? Andreas <maps.on@gmx.net>
2011-06-30 19:49 ` Steve Crawford <scrawford@pinpointresearch.com>
2011-07-01 02:17 ` Tim Landscheidt <tim@tim-landscheidt.de>
2011-07-01 02:43   ` Andreas <maps.on@gmx.net>
2011-06-30 19:57  Re: [SQL] How to remove a set of characters in text-columns ? Charlie <scorpdaddy@hotmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox