Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iaXnk-0006mN-4D for pgsql-general@arkaria.postgresql.org; Fri, 29 Nov 2019 04:22:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iaXng-0000tQ-Gx for pgsql-general@arkaria.postgresql.org; Fri, 29 Nov 2019 04:22:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iaXng-0000rF-5D for pgsql-general@lists.postgresql.org; Fri, 29 Nov 2019 04:22:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iaXna-0007sv-Ib for pgsql-general@lists.postgresql.org; Fri, 29 Nov 2019 04:22:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xAT4MO75018662; Thu, 28 Nov 2019 23:22:25 -0500 From: Tom Lane To: "David G. Johnston" cc: Rob Sargent , Antonio Silva , "pgsql-general@lists.postgresql.org" Subject: Re: using replace function In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Thu, 28 Nov 2019 18:54:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <18660.1575001344.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 28 Nov 2019 23:22:24 -0500 Message-ID: <18661.1575001344@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Thursday, November 28, 2019, Rob Sargent wrot= e: >> I want to replace a string (not a substring) in a field but making sure >> that the string in the full field. > I=E2=80=99d probably do something like: > Select case when a.col =3D =E2=80=98value=E2=80=99 then =E2=80=98new val= ue=E2=80=99 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