boolean
Learning Focus
Use this lesson to understand PostgreSQL boolean values and NULL-aware logic.
boolean Overview
- Values:
true,false, orNULL - Best for: feature flags, state markers, soft validation
Example
CREATE TABLE tasks (
task_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
done boolean NOT NULL DEFAULT false
);
Query patterns:
SELECT * FROM tasks WHERE done IS TRUE;
SELECT * FROM tasks WHERE done IS NOT TRUE; -- false or NULL
Common Pitfalls
| Pitfall | Consequence | Prevention |
|---|---|---|
Using = 1 / = 0 | Confusing or wrong | Use IS TRUE / IS FALSE |