using replace function

From: Antonio Silva <aolinto(dot)lst(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: using replace function
Date: 2019-11-28 21:09:14
Message-ID: CAE8g1gN26kaDGRvcRVr+gRgeySYmroswtCG0ZyCL2gFwsizJcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2019-11-28 22:48:07 Re: using replace function
Previous Message George Neuner 2019-11-28 21:07:06 Re: status of CURSORs after DISCONNECT