Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 052C69FB3CB for ; Mon, 2 Oct 2006 00:56:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 74109-03 for ; Mon, 2 Oct 2006 03:56:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 11E399FB3C6 for ; Mon, 2 Oct 2006 00:56:15 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id k923uAMP089468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 1 Oct 2006 21:56:13 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id k923uApQ042671; Sun, 1 Oct 2006 21:56:10 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id k923uAUK042670; Sun, 1 Oct 2006 21:56:10 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 1 Oct 2006 21:56:09 -0600 From: Michael Fuhr To: chester c young Cc: sql pgsql Subject: Re: regexp_replace usage Message-ID: <20061002035609.GA42444@winnie.fuhr.org> References: <20060929213112.13312.qmail@web54315.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060929213112.13312.qmail@web54315.mail.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=SPF_PASS, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200610/1 X-Sequence-Number: 26390 On Fri, Sep 29, 2006 at 02:31:12PM -0700, chester c young wrote: > column name in table bue has miscapitalized Mc names, eg, 'John Mcneil' > instead of 'John McNeil'. > > (this should be easy but) how do you construct the update query? > > also, regexp_string( 'Mcneil', 'Mc(.*)', initcap('\\1') ) => 'neil' > _not_ Neil' - is this correct? I assume you mean regexp_replace() as indicated in the subject. You're calling initcap() on the literal value '\\1'; the result, which is the same string, is then passed to regexp_replace(), so in effect you're calling regexp_replace('Mcneil', 'Mc(.*)', '\\1') Offhand I can't think of a way to do what you want with regexp_replace() but you could use PL/Perl. Something like this should work: CREATE FUNCTION mcfix(text) RETURNS text AS $$ $_[0] =~ s/\bMc([a-z])/Mc\u$1/g; return $_[0]; $$ LANGUAGE plperl IMMUTABLE STRICT; SELECT mcfix('John Mcneil'); mcfix ------------- John McNeil (1 row) You could use $_[0] =~ s/\b(Ma?c)([a-z])/$1\u$2/g; to change Mcdonald and Macdonald into McDonald and MacDonald, respectively. However, since both Macdonald and MacDonald are used, determining which is correct would be impossible. -- Michael Fuhr