Re: using replace function
Tom Lane <[email protected]>
| Newsgroups | gmane.comp.db.postgresql.general |
|---|---|
| Message-ID | <[email protected]> |
"David G. Johnston" <[email protected]> writes: > On Thursday, November 28, 2019, Rob Sargent <[email protected]> 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