SQL Boolean Data Type
Actually three-valued, not two — TRUE, FALSE, and NULL are all valid states.
What & Why
A BOOLEAN column holds TRUE or FALSE — but like every column type, it can also hold NULL, meaning "unknown" rather than either value. This is genuinely three-valued logic, not simple binary.
See How It Works
BOOLEAN RESULT — product.feedback
| id | user_id | nps_score | is_promoter |
|---|---|---|---|
| 1 | 101 | 9 | TRUE |
| 2 | 102 | NULL | NULL |
| 3 | 103 | 7 | FALSE |
| 4 | 104 | NULL | NULL |
The comparison `nps_score >= 8` produces a Boolean value: `TRUE` for 9, `FALSE` for 7, and `NULL` when the score itself is unknown.
EXAMPLE QUERY
SELECT id, user_id, nps_score,
nps_score >= 8 AS is_promoter
FROM product.feedback;Now You Try
Practice this concept
Product wants each feedback score classified as promoter, not promoter, or unknown when the NPS score is missing.
Available schema
productPrefix tables with product.table_name.
iduser_idnps_scoreis_promoterproduct.feedback| Column | Type |
|---|---|
| id | integer |
| user_id | integer |
| feature_id | integer |
| rating | integer |
| nps_score | integer |
| comment | text |
| created_at | timestamp with time zone |
| moderation_bucket | text |
query.sql
Sign up free to try it on a real business scenario