Data Types & NULLs
Learn SQL data types & nulls with practical examples and guided drills on dbSyntax.
Start with Data Types & NULLsData Types & NULLs
Type coercion and NULL handling are the two silent sources of wrong numbers in otherwise-correct queries. A string/int comparison that silen...
CAST
Explicit type conversion. CAST(expr AS type) (standard SQL) and expr::type (Postgres/DuckDB shorthand) behave the same. Most useful when rea...
IS NULL / IS NOT NULL
The only correct way to test for NULL. = and <> return unknown when either side is NULL, and unknown is not true, so those rows are filtered...
COALESCE
Return the first non-NULL argument, evaluated left to right. Standard SQL, supported everywhere, takes any number of arguments. The canonica...
IFNULL / NULLIF
Two small, easy-to-confuse NULL helpers. IFNULL(a, b) returns b when a is NULL, a two-argument COALESCE. NULLIF(a, b) returns NULL when a = ...