From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Rob Sargent <robjsargent@gmail.com>
Cc: Antonio Silva <aolinto.lst@gmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: using replace function
Date: Thu, 28 Nov 2019 23:22:24 -0500
Message-ID: <18661.1575001344@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbYHvu9J9Qb1CrqJ8gCPHxvH9vd7x6Yc=aZMx2Z66GD=g@mail.gmail.com>
References: <CAE8g1gN26kaDGRvcRVr+gRgeySYmroswtCG0ZyCL2gFwsizJcg@mail.gmail.com>
<E7D20D52-5606-4D78-8CD8-77BB17DB62AA@gmail.com>
<CAKFQuwbYHvu9J9Qb1CrqJ8gCPHxvH9vd7x6Yc=aZMx2Z66GD=g@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thursday, November 28, 2019, Rob Sargent <robjsargent@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, robjsargent@gmail.com, aolinto.lst@gmail.com
Subject: Re: using replace function
In-Reply-To: <18661.1575001344@sss.pgh.pa.us>
References: <CAE8g1gN26kaDGRvcRVr+gRgeySYmroswtCG0ZyCL2gFwsizJcg@mail.gmail.com> <E7D20D52-5606-4D78-8CD8-77BB17DB62AA@gmail.com> <CAKFQuwbYHvu9J9Qb1CrqJ8gCPHxvH9vd7x6Yc=aZMx2Z66GD=g@mail.gmail.com> <18661.1575001344@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox