Boolean Type
PostgreSQL has a genuine, first-class BOOLEAN type (often written BOOL) for representing true/false values. It takes up a single byte and, because NULL is also a valid value for any column, a boolean column actually supports three states rather than just two.
Three-valued logic
TRUE, FALSE, and NULL (unknown)
CREATE TABLE tasks (
task_id SERIAL PRIMARY KEY,
description TEXT NOT NULL,
is_complete BOOLEAN
);
INSERT INTO tasks (description, is_complete) VALUES
('Write report', TRUE),
('Review PR', FALSE),
('Plan next sprint', NULL); -- "not yet decided" / unknownValue | Meaning |
|---|---|
| Definitely true |
| Definitely false |
| Unknown / not applicable / not yet set |
This matters for WHERE clauses: WHERE is_complete = TRUE will not match rows where is_complete IS NULL, since comparing anything to NULL yields NULL (neither true nor false) rather than FALSE. If you want to explicitly include or exclude the unknown case, test for it directly with IS NULL or IS NOT NULL, or declare the column NOT NULL DEFAULT FALSE if a boolean field should never really be in an “unknown” state for your use case.
Flexible literal representations
PostgreSQL is unusually forgiving about how a boolean literal can be written. All of the following are accepted as valid input for TRUE, and each has a matching form for FALSE:
Many spellings, one type
SELECT 'true'::boolean, 't'::boolean, 'yes'::boolean, 'y'::boolean,
'on'::boolean, '1'::boolean;
-- every one of these evaluates to TRUE
SELECT 'false'::boolean, 'f'::boolean, 'no'::boolean, 'n'::boolean,
'off'::boolean, '0'::boolean;
-- every one of these evaluates to FALSEtrue | true | true | true | true | true false | false | false | false | false | false
Not every database has this
BOOLEANsupports three states:TRUE,FALSE, andNULL(unknown).Comparisons against
NULLnever returnTRUEorFALSE— useIS NULL/IS NOT NULLto test explicitly.PostgreSQL accepts many text spellings as boolean literals —
't','true','yes','1', and their opposites.This is a genuinely enforced, dedicated type — unlike databases that fake booleans with a small integer.