Null Handling Functions
Last updated
Was this helpful?
Was this helpful?
isDistinctFrom(col1, col2)SELECT isDistinctFrom(oldPrice, newPrice) AS price_changed
FROM priceHistory
LIMIT 10
-- Returns false when both are null, true when only one is nullisNotDistinctFrom(col1, col2)SELECT isNotDistinctFrom(shippingAddr, billingAddr) AS same_address
FROM orders
LIMIT 10coalesce(col1, col2, col3, ...)SELECT coalesce(preferredName, firstName, 'Unknown') AS displayName
FROM users
LIMIT 10CASE WHEN condition1 THEN result1
WHEN condition2 THEN result2
ELSE defaultResult
ENDSELECT orderId,
CASE WHEN total > 1000 THEN 'premium'
WHEN total > 100 THEN 'standard'
ELSE 'basic'
END AS tier
FROM orders
LIMIT 10nullIf(value1, value2)SELECT nullIf(status, 'N/A') AS status
FROM events
LIMIT 10
-- Returns null when status is 'N/A', otherwise returns the status valuebool_col1 AND bool_col2SELECT *
FROM orders
WHERE isPaid AND isShipped
LIMIT 10bool_col1 OR bool_col2SELECT *
FROM orders
WHERE isPaid OR isCOD
LIMIT 10NOT bool_colSELECT *
FROM orders
WHERE NOT isCancelled
LIMIT 10