Re: how to do a find and replace

From: Andrew Sullivan <ajs(at)crankycanuck(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to do a find and replace
Date: 2005-11-18 15:19:29
Message-ID: 20051118151929.GB28967@phlogiston.dyndns.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Nov 17, 2005 at 02:51:05PM -0800, Dawn Buie wrote:
> I'm just confused about how I should write code to update the selected
> items to remove the 'v.'
>
> Would I use substring? An example would be much appreciated.

You need a combination of overlay and location. The following will
work if you always have _only_ 'v.' in there in the one place you
want it. If it is too early in the string, this _won't_ work:

andrewtest=# SELECT version();
version
-------------------------------------------------------------------------------------------------------
PostgreSQL 7.4.7 on i386-pc-linux-gnu, compiled by GCC
i386-linux-gcc (GCC) 3.3.5 (Debian 1:3.3.5-12)
(1 ligne)

andrewtest=# SELECT * from mytable ;
location
-----------------------------
/0/v.myimage.jpg
/0/v.myotherimage.jpg
/0/v.myvthotherimage.jpg
/0/v.myvthotherv.image.jpg
(4 lignes)

Note that I've fiddled with the initial spacing here, in case that
hasn't been totally consistent either. This is for illustration.

andrewtest=# select overlay(location placing '' from (position('v.'
in location)) for 2) from mytable;
overlay
---------------------------
/0/myimage.jpg
/0/myotherimage.jpg
/0/myvthotherimage.jpg
/0/myvthotherv.image.jpg
(4 lignes)

Note here that the _second_ 'v.' in the last entry doesn't get pulled
out. These functions work on the first hit, so this is as expected.
But if you have something like '/v.0/v.myimage.jpeg' you'll not lose
the 'v.' you want, I expect.

A

--
Andrew Sullivan | ajs(at)crankycanuck(dot)ca
The whole tendency of modern prose is away from concreteness.
--George Orwell

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Dean Gibson (DB Administrator) 2005-11-18 21:16:21 Re: Export to XML
Previous Message Andrew Sullivan 2005-11-18 15:06:05 Re: idea for a geographically distributed database: how best to implement?