Replace empty strings with NULLs

Replace empty strings with NULLs

Explore this snippet here.

Description

An essential part of cleaning a new data source is deciding how to treat missing values. The Snowflake function IFF can help with replacing empty values with something else:

with data as (
  select * from (values ('a'), ('b'), (''), ('d')) as data (str)
)

select
  iff(length(str) = 0, null, str) str
from data
STR
a
b
NULL
d

Out of curiosity, why would you not opt for a
IFF(str = ‘’, NULL, str)

Hi Robin,

No particular reason tbh. You can see it returns the same results here: