Skip to main content

boolean

Learning Focus

Use this lesson to understand PostgreSQL boolean values and NULL-aware logic.

boolean Overview

  • Values: true, false, or NULL
  • 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

PitfallConsequencePrevention
Using = 1 / = 0Confusing or wrongUse IS TRUE / IS FALSE

What's Next