QuestionQ273

VerifiedData Processing & Transformations

Which Databricks SQL predicate correctly performs a null-safe equality comparison, so that rows are matched when both sides are NULL or when both sides are equal non-NULL values?

Explanation

Databricks SQL (Spark SQL) provides the null-safe equal operator <=>, which is specifically designed to return TRUE when both operands are NULL, TRUE when both operands are non-NULL and equal, and FALSE otherwise. Unlike the standard = operator, <=> never evaluates to NULL/UNKNOWN, making it the correct construct for null-safe equality comparisons such as customer_id <=> :cid. The other options either rely on the standard = operator (which yields NULL/UNKNOWN instead of TRUE when comparing NULLs), use COALESCE as an imprecise workaround that can misfire on legitimate empty-string values, or construct flawed boolean logic that does not correctly express null-safe equality semantics.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!