Boolean

Learn how to use the PostgreSQL BOOLEAN data type to store true, false, and NULL values, including accepted literal formats and default value patterns.

4 min read · Last updated: March 2026 · Back to overview

Quick Answer

The PostgreSQL BOOLEAN type stores three values: true, false, and NULL. It accepts multiple literal formats including TRUE/FALSE, 't'/'f', 'yes'/'no', and '1'/'0', and uses 1 byte of storage.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

PostgreSQL provides a single BOOLEAN data type (abbreviated BOOL) that can hold three states: true, false, and NULL. It uses 1 byte of storage and is the standard choice for flag columns, feature toggles, and any binary yes/no attribute.

Accepted boolean literal values

PostgreSQL accepts a wide range of input literals for boolean columns. All non-keyword literals must be quoted:

  • True: true, 't', 'true', 'y', 'yes', '1'
  • False: false, 'f', 'false', 'n', 'no', '0'

Leading and trailing whitespace is ignored for quoted values.

Creating and querying a boolean column

CREATE TABLE stock_availability (
  product_id INT PRIMARY KEY,
  available  BOOLEAN NOT NULL
);

Insert rows using various accepted literals:

INSERT INTO stock_availability (product_id, available)
VALUES
  (100, TRUE),
  (200, FALSE),
  (300, 't'),
  (400, '1'),
  (500, 'yes'),
  (700, 'no'),
  (800, '0');

Query available products by using the column name directly — no comparison operator needed:

SELECT * FROM stock_availability WHERE available;
product_id | available
------------+-----------
       100 | t
       300 | t
       400 | t
       500 | t

Find unavailable products using NOT:

SELECT * FROM stock_availability WHERE NOT available;
product_id | available
------------+-----------
       200 | f
       700 | f
       800 | f

Setting default values for boolean columns

Set a default on an existing table using ALTER TABLE:

ALTER TABLE stock_availability
ALTER COLUMN available SET DEFAULT FALSE;

Now inserting without specifying available defaults to false:

INSERT INTO stock_availability (product_id) VALUES (900);

SELECT * FROM stock_availability WHERE product_id = 900;
product_id | available
------------+-----------
       900 | f

For new tables, add the default inline in the column definition:

CREATE TABLE feature_flags (
  flag_name VARCHAR(100) PRIMARY KEY,
  is_enabled BOOL DEFAULT false
);

Production tips

  • Use the boolean column directly in WHERE clauses (WHERE is_active) rather than WHERE is_active = TRUE — it is shorter and equally readable.
  • Always specify NOT NULL with a DEFAULT for flag columns to prevent three-valued logic surprises with NULL in WHERE conditions.
  • Partial indexes on boolean columns are highly efficient: CREATE INDEX ON users (id) WHERE is_active indexes only active rows.
  • Avoid storing boolean values as integers (0/1) in PostgreSQL — the native BOOLEAN type is more readable and type-safe.

Reference: PostgreSQL documentation — Boolean Type.

Continue in PostgreSQL Data Types: CHAR, VARCHAR, and TEXT.

Related in this section: CHAR, VARCHAR, and TEXT · NUMERIC · DOUBLE PRECISION

Frequently Asked Questions

What values can a PostgreSQL BOOLEAN column store?

A BOOLEAN column stores true, false, or NULL. PostgreSQL is flexible about input — it accepts TRUE, FALSE, 't', 'f', 'true', 'false', 'y', 'n', 'yes', 'no', '1', and '0'. All string literals must be quoted; only bare true and false are unquoted.

How do I query rows where a boolean column is true?

You can use the column name directly without a comparison: SELECT * FROM t WHERE active; This is equivalent to WHERE active = TRUE. For false values, use WHERE NOT active or WHERE active = FALSE.

How do I set a default value for a boolean column?

Use a DEFAULT clause: CREATE TABLE t (is_active BOOL DEFAULT TRUE). For an existing table: ALTER TABLE t ALTER COLUMN is_active SET DEFAULT FALSE.

Is BOOLEAN the same as BOOL in PostgreSQL?

Yes. BOOL is the short alias for BOOLEAN. Both are identical in behavior and storage (1 byte). Either can be used in CREATE TABLE or ALTER TABLE statements.

How does PostgreSQL store boolean values internally?

PostgreSQL uses 1 byte to store a boolean value. True is stored as 1 and false as 0. NULL is handled separately as a null bitmap in the row header, not as a specific byte value.