> This page location: PostgreSQL Data Types > Boolean
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL Boolean Data Type with Practical Examples

**Summary**: in this tutorial, you will learn about the PostgreSQL Boolean data type and how to use it in designing database tables.

## Introduction to the PostgreSQL Boolean type

![PostgreSQL Boolean](https://neon.com/postgresqltutorial/PostgreSQL-Boolean-300x146.png?alignright)
PostgreSQL supports a single Boolean [data type](https://neon.com/postgresql/postgresql-tutorial/postgresql-data-types): `BOOLEAN` that can have three values: `true`, `false` and `NULL`.

PostgreSQL uses one byte for storing a boolean value in the database. The `BOOLEAN` can be abbreviated as `BOOL`.

In standard SQL, a Boolean value can be `TRUE`, `FALSE`, or `NULL`. However, PostgreSQL is quite flexible when dealing with `TRUE` and `FALSE` values.

The following table shows the valid literal values for `TRUE` and `FALSE` in PostgreSQL.

| True   | False   |
| ------ | ------- |
| true   | false   |
| 't'    | 'f '    |
| 'true' | 'false' |
| 'y'    | 'n'     |
| 'yes'  | 'no'    |
| '1'    | '0'     |

Note that the leading or trailing whitespace does not matter and all the constant values except for `true` and `false` must be enclosed in single quotes.

## PostgreSQL Boolean examples

Let's take a look at some examples of using the PostgreSQL Boolean data type.

First, [create a new table](https://neon.com/postgresql/postgresql-tutorial/postgresql-create-table) called `stock_availability` to log which products are available.

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

Second, [insert some sample data](https://neon.com/postgresql/postgresql-tutorial/postgresql-insert) into the `stock_availability` table. We use various literal values for the boolean values.

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

Third, check for the availability of products:

```sql
SELECT *
FROM stock_availability
WHERE available = 'yes';
```

```text
 product_id | available
------------+-----------
        100 | t
        300 | t
        400 | t
        500 | t
        600 | t
(5 rows)
```

You can imply the true value by using the Boolean column without any operator. For example, the following query returns all available products:

```sql
SELECT *
FROM stock_availability
WHERE available;
```

Similarly, if you want to look for `false` values, you compare the value of the Boolean column against any valid Boolean constants.

The following query returns the products that are not available.

```sql
SELECT
  *
FROM
  stock_availability
WHERE
  available = 'no';
```

```text
 product_id | available
------------+-----------
        200 | f
        700 | f
        800 | f
(3 rows)
```

Alternatively, you can use the `NOT` operator to check if values in the Boolean column are false like this:

```sql
SELECT
  *
FROM
  stock_availability
WHERE
  NOT available;
```

## Set the default values for Boolean columns

To set a default value for an existing Boolean column, you use the `SET DEFAULT` clause in the [ALTER TABLE](https://neon.com/postgresql/postgresql-tutorial/postgresql-alter-table) statement.

For example, the following `ALTER TABLE` statement sets the default value for the `available` column in the `stock_availability` table:

```sql
ALTER TABLE stock_availability
ALTER COLUMN available
SET DEFAULT FALSE;
```

If you insert a row without specifying the value for the `available` column, PostgreSQL will use `FALSE` by default:

```sql
INSERT INTO stock_availability (product_id)
VALUES (900);
```

```sql
SELECT *
FROM stock_availability
WHERE product_id = 900;
```

```text
 product_id | available
------------+-----------
        900 | f
(1 row)
```

Likewise, if you want to set a default value for a Boolean column when you [create a table](https://neon.com/postgresql/postgresql-tutorial/postgresql-create-table), you use the `DEFAULT` constraint in the column definition as follows:

```sql
CREATE TABLE boolean_demo (
   ...
   is_ok BOOL DEFAULT 't'
);
```

## Summary

- Use the PostgreSQL `BOOLEAN` datatype to store the boolean data.

---

## Related docs (PostgreSQL Data Types)

- [CHAR, VARCHAR, and TEXT](https://neon.com/postgresql/postgresql-tutorial/postgresql-char-varchar-text)
- [NUMERIC](https://neon.com/postgresql/postgresql-tutorial/postgresql-numeric)
- [DOUBLE PRECISION](https://neon.com/postgresql/postgresql-tutorial/postgresql-double-precision-type)
- [REAL](https://neon.com/postgresql/postgresql-tutorial/postgresql-real-data-type)
- [Integer](https://neon.com/postgresql/postgresql-tutorial/postgresql-integer)
- [SERIAL](https://neon.com/postgresql/postgresql-tutorial/postgresql-serial)
- [DATE](https://neon.com/postgresql/postgresql-tutorial/postgresql-date)
- [TIMESTAMP](https://neon.com/postgresql/postgresql-tutorial/postgresql-timestamp)
- [Interval](https://neon.com/postgresql/postgresql-tutorial/postgresql-interval)
- [TIME](https://neon.com/postgresql/postgresql-tutorial/postgresql-time)
- [UUID](https://neon.com/postgresql/postgresql-tutorial/postgresql-uuid)
- [JSON](https://neon.com/postgresql/postgresql-tutorial/postgresql-json)
- [HSTORE](https://neon.com/postgresql/postgresql-tutorial/postgresql-hstore)
- [Array](https://neon.com/postgresql/postgresql-tutorial/postgresql-array)
- [User-defined Data Types](https://neon.com/postgresql/postgresql-tutorial/postgresql-user-defined-data-types)
- [Enum](https://neon.com/postgresql/postgresql-tutorial/postgresql-enum)
- [XML](https://neon.com/postgresql/postgresql-tutorial/postgresql-xml-data-type)
- [BYTEA](https://neon.com/postgresql/postgresql-tutorial/postgresql-bytea-data-type)
- [Composite Types](https://neon.com/postgresql/postgresql-tutorial/postgresql-composite-types)
