From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Rob Sargent <robjsargent(at)gmail(dot)com> |
Cc: | Antonio Silva <aolinto(dot)lst(at)gmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: using replace function |
Date: | 2019-11-29 01:54:38 |
Message-ID: | CAKFQuwbYHvu9J9Qb1CrqJ8gCPHxvH9vd7x6Yc=aZMx2Z66GD=g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thursday, November 28, 2019, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:
>
>
> > On Nov 28, 2019, at 1:09 PM, Antonio Silva <aolinto(dot)lst(at)gmail(dot)com>
> wrote:
> >
> > Hello list
> >
> > I want to replace a string (not a substring) in a field but making sure
> that the string in the full field.
> >
> > In the example below since 'blue' is not the full text in 'blue shark'
> there should not have a replacement.
> >
> > How to say "replace only with 'blue' if it is the full string in the
> field".
> >
> > With REPLACE I get:
> >
> > SELECT REPLACE('blue shark','blue','blue fish');
> > replace
> > -----------------
> > blue fish shark
> > (1 row)
> >
> > but I would like to get:
> >
> > SELECT REPLACE('blue shark','blue','blue fish');
> > replace
> > ------------
> > blue shark
> > (1 row)
> >
> > Thanks a lot
> >
> > Antonio Olinto
>
> does this help?
> select replace (a.col, ‘value’, ’new value’) where a.col = ‘value’;
>
>
I’d probably do something like:
Select case when a.col = ‘value’ then ‘new value’ else a.col end from a;
I suspect adding where a.col = ‘value’ isn’t viable. If it is then:
Select ‘new value’ from a where a.col = ‘value’;
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2019-11-29 04:22:24 | Re: using replace function |
Previous Message | Rob Sargent | 2019-11-28 22:48:07 | Re: using replace function |