Page 1 of 1

Empty string handling...

Posted: Tue May 09, 2017 1:59 pm
by Julie
Hi all,

Anyone know how to replace an empty string (i.e. '') with another string?

This works:

dbadmin=> select replace('TEST', 'TEST', 'FOUND');
replace
---------
FOUND
(1 row)

But this does not:

dbadmin=> select replace('', '', 'FOUND');
replace
---------

(1 row)

Re: Empty string handling...

Posted: Tue May 09, 2017 5:26 pm
by JimKnicely
Hi Julie,

You can use a CASE statement:

dbadmin=> select case '' when '' then 'FOUND' else '' end;
case
-------
FOUND
(1 row)