Re: changing partial data

From: "Thalis A(dot) Kalfigopoulos" <thalis(at)cs(dot)pitt(dot)edu>
To: Peter Choe <choepete(at)mindspring(dot)com>
Cc: postgres <pgsql-general(at)postgresql(dot)org>
Subject: Re: changing partial data
Date: 2001-07-11 19:21:33
Message-ID: Pine.LNX.4.21.0107111515290.7168-100000@aluminum.cs.pitt.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


UPDATE tablename SET description=(substring(description for position('test' in description))||'exam'||substring(description from position('test' in description)+char_length('test')));

Keep in mind that this will only replace the first occurence of the word 'test' in the description and that description should have 'test' in it. So better to add a WHERE condition to youw update.

cheers,
thalis

On Wed, 11 Jul 2001, Peter Choe wrote:

> is there a way in postgres to change just a part of a text data in a
> column. for example if i have a column called description with the
> following data:
>
> +---------------------+
> | description |
> +---------------------+
> | this is a test. |
> +---------------------+
>
> and i want to change the word test to exam, can i just replace the word
> test rather than reentrying to who value of the column?
>
> so, instead of:
>
> update foo set description='this is a exam' where description='this is a
> test';
>
> can i do something like:
>
> update foo replace test with exam;
>
> peter choe
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message dennis@zserve.com 2001-07-11 19:47:44 Table Size/Performance
Previous Message Bruce Momjian 2001-07-11 19:02:53 Re: Bug in createlang?