Problems / Blank vs NULL / Editorial
CASE
comments IS NULL
'missing'
comments = ''
NULLIF(TRIM(comments), '') IS NULL
'blank'
TRIM
''
NULLIF(x, '')
IS NULL
ELSE 'has_text'
comment_id
NULL and empty string are not the same thing (unless you're on Oracle, which infamously conflates them). NULL means the value was never captured; '' and ' ' mean a value was captured but is content-free. Pipelines usually need to distinguish "never asked" from "answered with nothing".
' '
NULLIF(TRIM(col), '') is the workhorse idiom here: it canonicalizes every flavor of blank into NULL, after which the regular NULL machinery (IS NULL, COALESCE, COUNT(col)) treats blanks and NULLs uniformly. Flip it around — COALESCE(NULLIF(TRIM(col), ''), 'default') — and you get "replace blanks and NULLs with a default" in one line.
NULLIF(TRIM(col), '')
COALESCE
COUNT(col)
COALESCE(NULLIF(TRIM(col), ''), 'default')
Solve Blank vs NULL yourself →