From: | Jeff Eckermann <jeckermann(at)verio(dot)net> |
---|---|
To: | "'Peter Choe'" <choepete(at)mindspring(dot)com>, postgres <pgsql-general(at)postgresql(dot)org> |
Subject: | RE: changing partial data |
Date: | 2001-07-12 14:28:23 |
Message-ID: | 08CD1781F85AD4118E0800A0C9B8580B094B2D@NEZU |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
If you think you may want to do this kind of thing again, you might consider
creating a function to make it easier. At present, there is no builtin
PostgreSQL function that will do it.
Perl is especially handy for this sort of thing:
CREATE FUNCTION s(text, text)
RETURNS text AS '
return s/@_[0]/@_[1]/;
' LANGUAGE 'plperl';
CREATE FUNCTION s(text, text, text)
RETURNS text AS '
return s/@_[0]/@_[1]/@_[2];
' LANGUAGE 'plperl';
Overloading the function in this way allows for optional flags. The effect
is to get you pretty close to the actual Perl syntax, with the same
functionality.
If you want to try this, check that you have plperl installed: check the
docs ("Procedural Languages") for more info.
> -----Original Message-----
> From: Peter Choe [SMTP:choepete(at)mindspring(dot)com]
> Sent: Wednesday, July 11, 2001 12:48 PM
> To: postgres
> Subject: [GENERAL] changing partial data
>
> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2001-07-12 14:37:49 | Re: Re: Pg7.2 (was: vacuum and 24/7 uptime) |
Previous Message | Bruce Momjian | 2001-07-12 14:25:43 | Re: Pg7.2 (was: vacuum and 24/7 uptime) |