pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: Jeff Eckermann <jeckermann@verio.net>
To: 'Josh Berkus' <josh@agliodbs.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: search/replace in update
Date: Fri, 15 Jun 2001 12:30:39 +0100
Message-ID: <01061512303902.01056@gary.ringways.co.uk> (raw)
In-Reply-To: <08CD1781F85AD4118E0800A0C9B8580B094AD7@NEZU>
References: <08CD1781F85AD4118E0800A0C9B8580B094AD7@NEZU>

Hi Jeff,

Thanks for the response.  Although I've never used functions before, I kinda 
follow what you're doing.  Presumably the parameters are field, old string, 
new string.

However, I have two problems.

1) I don't know how I would call that function
2) when I tried to create the function it failed saying unrecognised 
landuage. The message I got was: 

ERROR:  Unrecognized language specified in a CREATE FUNCTION: 'plperl'.  
Recognized languages are sql, C, internal and the created procedural 
languages.

I'm running postgresql 7.0.2-2 installed from rpms onto RH6.1.

Gary

On Thursday 14 June 2001  4:42 pm, Jeff Eckermann wrote:
> Which function would you be suggesting?  I hope not "translate".  That
> works on characters, not strings.  Easy to confuse if you don't read
> closely enough, as I found to my cost.
> Easiest way using these functions would be:
> UPDATE table
> SET mobile_number = '07889' || substr (mobile_number, 5)
> WHERE mobile_number LIKE '0589%';
> Alternatively, you could define a generic search/replace function like:
> CREATE FUNCTION search_replace (text, text, text)
> RETURNS text AS '
> RETURN @_[0] =~ s/@_[1]/@_[2]/
> ' LANGUAGE 'plperl';
> Which would be available anytime for similar purposes (credit to Tom Lane
> for the idea).
>
> > -----Original Message-----
> > From:	Josh Berkus [SMTP:josh@agliodbs.com]
> > Sent:	Thursday, June 14, 2001 9:52 AM
> > To:	Gary Stainburn
> > Cc:	pgsql-sql@postgresql.org
> > Subject:	Re: search/replace in update
> >
> > Gary,
> >
> > > This means that e.g. all mobile numbers that used to start 0589 now
> > > start 07889.
> > >
> > > Is there a way in SQL to update the phone number in-place?
> >
> > Postgresql has a nifty string substitution function.  For this and other
> > character manipulation functions, see:
> >
> > http://www.postgresql.org/idocs/index.php?functions-string.html
> >
> > You should be able to fairly easily swap out "07889" and replace it with
> > "0589".
> >
> > -Josh
> >
> >
> >
> > ______AGLIO DATABASE SOLUTIONS___________________________
> >                                        Josh Berkus
> >   Complete information technology      josh@agliodbs.com
> >    and data management solutions       (415) 565-7293
> >   for law firms, small businesses        fax 621-2533
> >     and non-profit organizations.      San Francisco
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster



view thread (7+ messages)  latest in thread

Message-ID: <01061512303902.01056@gary.ringways.co.uk>
Permalink:  ../01061512303902.01056@gary.ringways.co.uk/
Also on:    postgresql.org/message-id/01061512303902.01056@gary.ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk, jeckermann@verio.net, josh@agliodbs.com
  Subject: Re: search/replace in update
  In-Reply-To: <01061512303902.01056@gary.ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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