Loading lesson...
Where pennies vanish and NULLs defy
Where pennies vanish and NULLs defy
Topics covered: BOOLEAN and NULL logic, DECIMAL precision and scale, TIMESTAMP vs TIMESTAMP WITH TIME ZONE, Time zones and UTC handling, TRY_CAST and implicit casts
Truth Table Surprises Boolean Filtering Patterns
Common Configurations Avoiding Numeric Pitfalls Integer division and floating-point approximation cause subtle bugs in calculations. Which type would you use for a financial total column? Choosing the right numeric type is critical for financial accuracy.
SQL provides two primary temporal types that seem similar but solve fundamentally different problems. Choosing the wrong one causes bugs that only appear when users span multiple time zones or when daylight saving time transitions happen. Choosing between these types depends on whether your value represents a calendar label or a specific moment in time. Choosing Temporal Types Select the right temporal type based on whether you need time precision and timezone awareness.
Time zones are one of the most error-prone areas in data engineering. A timestamp without timezone context is ambiguous. Is "2025-03-15 14:00:00" in UTC? Eastern Time? The server's timezone? Incorrect assumptions lead to data shifted by hours, causing wrong aggregations and confused stakeholders. Timezone Best Practices Following these guidelines helps avoid timezone-related bugs in global applications. Always use full IANA timezone names like America/New_York rather than abbreviations like EST,
Implicit Type Coercion SQL automatically converts between compatible types in certain situations. This "implicit conversion" happens silently, which can be both convenient and dangerous. Validating and casting data at ingestion time is far more efficient than casting at every query. Store data in the correct type once during ETL so all subsequent reads pay no conversion cost.