How to COALESCE for empty strings and NULL values?

Do not create a user function is you want speed. Instead of this:

coalescenonempty(col1,col2||'blah',col3,'none');

do this:

COALESCE(NULLIF(col1,''),NULLIF(col2||'blah',''),NULLIF(col3,''),'none');

That is, for each non-constant parameter, surround the actual parameter with NULLIF( x ,'').

Leave a Comment