From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | Rob Sargent <robjsargent(at)gmail(dot)com>, 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 04:22:24 |
Message-ID: | 18661.1575001344@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thursday, November 28, 2019, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:
>> I want to replace a string (not a substring) in a field but making sure
>> that the string in the full field.
> I’d probably do something like:
> Select case when a.col = ‘value’ then ‘new value’ else a.col end from a;
Yeah, this. You could wrap it up in a SQL function if you want the
same level of notational convenience as replace().
Another possibility is regexp_replace with an anchored pattern, but
that would potentially require escaping regexp metacharacters in the
pattern, so the PITA factor is high. And I doubt it'd be faster than
the CASE solution.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Nandakumar M | 2019-11-29 07:40:07 | Re: Rows violating Foreign key constraint exists |
Previous Message | David G. Johnston | 2019-11-29 01:54:38 | Re: using replace function |