Reputation: 135
What should be the code for handling blanks in snowflake?
for NULL, we do like
nvl (col1 , 'NA')
However, for blank or empty space etc what is the code in snowflake?
Upvotes: 0
Views: 5705
Reputation: 176094
For handling '', ' ' or NULL the following code could be used:
SELECT col, COALESCE(NULLIF(TRIM(col), ''), 'NA')
FROM VALUES ('text'), (NULL), (''), (' '), (' ') AS s(col);
Output:
Rationale:
Upvotes: 1
Reputation: 4608
You can do it with a CASE or IFF, for example:
select
column1,
case
when column1='' then 'blank'
when column1=' ' then 'space'
else 'NA'
end as result
from (values(''),(' '),('x')) v;
I get back:
With IFF you can try something like:
set a = ' ';
select iff($a = ' ', 'space', 'NA');
set b = '';
select iff($b = '', 'blank', 'NA');
Upvotes: 0