Null, Zero, and Empty Text in SQL
SQL null indicates missing or unknown data under the applicable operation. Zero and empty text can be present values with distinct meanings.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a rating
A null rating may mean unrated. A numeric rating of zero can be a submitted score. An empty text comment can mean the sender supplied no visible words. See unset, empty, and zero.
Choose a predicate
A null check is a dedicated operation, such as IS NULL. Ordinary comparison can yield unknown when null participates. SQL three-valued logic explains why null comparisons need care.[1][2]
Compare three different stored observations
In a measurements table, value zero can be an observed number, while null can mean no numeric observation. In a text column, an empty string can mean submitted text of length zero. Neither value necessarily implies that another row is missing. See unset, empty and zero.
Numeric list: 0, null, 6
Count of rows: 3
Count of non-null readings: 2
Mean of non-null values: 3
Use explicit null checks in predicates
A comparison between an ordinary value and null generally yields unknown under SQL's three-valued logic. Use the database's null tests when checking presence. Test zero together with null so their treatment cannot be conflated.