FOUNDATIONS-5: Handling Missing Data: NULL, COALESCE & Blank Strings
Track: Analytics Foundations • Difficulty: Beginner • Mastery Points: 100 PTS
Business Problem Scenario
In real databases, missing data shows up in two sneaky ways: actual NULLs and blank empty strings (' '). If you don't handle both, automated email reports crash or skip customers.
Engineering Objective
Clean NULL and blank emails cleanly using COALESCE and NULLIF. • Expected Columns: contact_id, full_name, contact_email • Logic: - Trim whitespace and lowercase valid emails. - Treat '' (empty string) as missing using NULLIF(..., ''). - Replace missing emails with 'no-email@on-file.invalid'. - Order by contact_id ASC.
Target Table: bronze.contacts (contact_id TEXT, full_name TEXT, email TEXT)
Verification & Architecture Insights
`NULLIF(x, '')` turns empty strings into `NULL`, and `COALESCE(val, fallback)` picks the first non-NULL value. Combining them is the safest pattern for cleaning messy text columns.