Shows how to detect, replace, and transform NULL values in Snowflake SQL using built-in functions.
NULL represents missing or unknown data. It surfaces when a column value is absent, a calculation returns no result, or data is loaded with empty fields.
Snowflake offers NVL, COALESCE, IFNULL, NULLIF, and NVL2. These functions let you swap, detect, or transform NULL values in SELECT, WHERE, and JOIN clauses.
NVL(expression, replacement) returns replacement when expression is NULL.Use NVL(o.total_amount, 0) to avoid NULLs in revenue reports.
COALESCE checks each argument sequentially and returns the first non-NULL. Helpful when you have multiple fallback columns such as p.sale_price, p.price, 0.
NULLIF(expr1, expr2) returns NULL when the two expressions match; otherwise it returns expr1. Convert sentinel values like 0 or '' into NULL for cleaner analytics.
NVL2(expr, value_if_not_null, value_if_null) chooses between two outputs based on whether expr is NULL.This avoids an extra CASE expression.
Use IS NULL or IS NOT NULL. Comparisons with '=' or '!=' never match NULL, leading to empty result sets.
Standardize default replacements, keep data types aligned, document business meaning of NULLs, and audit NULL counts to spot data quality issues.
.
Use COUNT(*) - COUNT(column) to get the number of NULL rows because COUNT(column) ignores NULLs.
Yes. Add NULL_IF=('','NULL') to your COPY INTO command so Snowflake maps empty strings or the word "NULL" to actual NULL values.
COALESCE is a lightweight expression. Performance impact is negligible compared with I/O and join costs. Keep predicates selective to minimize scanned data.