Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id F3A43650DBC for ; Wed, 2 Jul 2008 15:07:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 52985-03 for ; Wed, 2 Jul 2008 15:07:38 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by postgresql.org (Postfix) with ESMTP id B634664FE0F for ; Wed, 2 Jul 2008 15:07:39 -0300 (ADT) Received: from Courts-MTA by gwmta.wicourts.gov with Novell_GroupWise; Wed, 02 Jul 2008 13:07:37 -0500 Message-Id: <486B7D9F.EE98.0025.0@wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 7.0.3 Date: Wed, 02 Jul 2008 13:07:29 -0500 From: "Kevin Grittner" To: "Karen Stone" , "Naomi Walker" , "pgsql-admin@postgresql.org" Subject: Re: Change a character in a text field References: <486A9A5E.9070905@mhs.mphasis.com> <486A59E1.EE98.0025.0@wicourts.gov> <09BDF9F0EAD32745A823E1865E6C45F3C99AE3@ecimail.eldocomp.com> In-Reply-To: <09BDF9F0EAD32745A823E1865E6C45F3C99AE3@ecimail.eldocomp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/36 X-Sequence-Number: 29646 >>> Karen Stone wrote: >>> Is there some way with a SQL state to interrogate a text field, and >>> replace characters. >>> >>> For example, we would like all "|"'s to be changed to something else, >>> on >>> a regular basis... >> >> It sounds like you might want to look at the regexp_replace function: >> >> http://www.postgresql.org/docs/8.3/interactive/functions-matching.html#F >> UNCTIONS-POSIX-REGEXP >> >> Be sure to use a WHERE clause on your UPDATE with the ~ operator. > > Can you please provide a complete example of how to use this in the > update command? ie... how do we select the table/field that we want to > interrogate and make the change to? Assuming standard_conforming_strings is on, this (untested) should do it: UPDATE sometable SET somecolumn = regexp_replace(somecolumn, '\|', 'something else', 'g') WHERE somecolumn ~ '\|'; If standard_conforming_strings is off, double the backslashes. -Kevin