Empty string handling...

Moderator: NorbertKrupa

Post Reply
User avatar
Julie
Master
Master
Posts: 221
Joined: Thu Apr 19, 2012 9:29 pm

Empty string handling...

Post by Julie » Tue May 09, 2017 1:59 pm

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)
Thanks,
Juliette

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Empty string handling...

Post by JimKnicely » Tue May 09, 2017 5:26 pm

Hi Julie,

You can use a CASE statement:

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

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

Post Reply

Return to “Vertica SQL”