ENUM types
Learning Focus
Use this lesson to model finite status values using PostgreSQL ENUM and understand maintenance tradeoffs.
Concept Overview
Enums restrict a column to a set of named values.
CREATE TYPE order_status AS ENUM ('pending', 'paid', 'cancelled');
Example
CREATE TABLE orders (
order_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
status order_status NOT NULL DEFAULT 'pending'
);
Add a new value:
ALTER TYPE order_status ADD VALUE 'refunded';
When to Use vs Avoid
Use enums when:
- the set is small and changes rarely
Avoid enums when:
- the set changes frequently (consider a lookup table + FK)