Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Compare PostgreSQL ENUM types against VARCHAR with CHECK constraints. Analyze table rewrite locks, storage bytes, and zero-downtime migration trade-offs.
Quick answer
PostgreSQL ENUM types store enumerated values as internal 4-byte integers, saving storage and enforcing type safety across the database. VARCHAR columns with CHECK constraints consume slightly more bytes but offer simpler zero-downtime schema migrations, easy value removals, and seamless cross-database portability.
FAQs
Can I remove a value from a PostgreSQL ENUM without recreating it?
No. PostgreSQL does not support dropping a value from an enum type. You must create a new enum type, alter the table column to the new type, and drop the old enum.
Does an ENUM sort alphabetically or in order of creation?
A PostgreSQL ENUM sorts in the order values were declared when the type was created, not alphabetically. For example, 'draft' < 'submitted' based on declaration order.
How much storage does an ENUM save compared to VARCHAR?
An ENUM always consumes 4 bytes per row. A VARCHAR consumes string length plus 1 byte. For an 8-character string, an ENUM saves 5 bytes per row.
Can I use an ENUM across multiple tables in PostgreSQL?
Yes. Once created with CREATE TYPE, an enum type can be referenced by columns across multiple tables in the same database.
Build fast text search directly in PostgreSQL without external search engines. Master to_tsvector, to_tsquery, relevance ranking with ts_rank, and GIN indexes.
Relational schemas regularly store discrete categorical attributes: order status (pending, shipped, delivered), subscription tier (free, pro, enterprise), or user role (admin, editor, viewer). In PostgreSQL, engineers must decide between two primary approaches: creating a custom ENUM data type or using a VARCHAR column validated by a CHECK constraint.
While both approaches enforce data validation, they diverge drastically when schemas evolve. Adding or removing values from an ENUM type involves specific catalog locking behavior, while CHECK constraints can be validated concurrently without locking tables. Evaluating storage savings against migration agility determines the right choice for your workload.
Option 1: PostgreSQL native ENUM types
PostgreSQL allows you to define custom enumerated types using CREATE TYPE ... AS ENUM.
Defining and using a PostgreSQL ENUM type
-- Create custom enum type in database catalogCREATE TYPE order_status_type AS ENUM ( 'draft', 'submitted', 'processing', 'shipped', 'cancelled');-- Use enum type in table definitionCREATE TABLE customer_orders ( order_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, customer_id INT NOT NULL, current_status order_status_type NOT NULL DEFAULT 'draft', total_amount NUMERIC(10, 2) NOT NULL);
According to the PostgreSQL enumerated types documentation, each enum value is stored internally as a 4-byte OID integer in system catalog tables. Regardless of how long the label string is, storing 'processing' consumes only 4 bytes in the table heap page.
Option 2: VARCHAR or TEXT with CHECK constraints
The alternative pattern uses standard VARCHAR or TEXT data types paired with an explicit CHECK constraint.
Using CHECK constraints for categorical validation
CREATE TABLE customer_orders_check ( order_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, customer_id INT NOT NULL, current_status VARCHAR(20) NOT NULL DEFAULT 'draft', total_amount NUMERIC(10, 2) NOT NULL, -- Table-level or column-level CHECK constraint CONSTRAINT chk_valid_order_status CHECK (current_status IN ( 'draft', 'submitted', 'processing', 'shipped', 'cancelled' )));
A VARCHAR(20) column stores the text string directly plus a 1-byte length header. For a short value like 'draft', storage is 6 bytes on disk (only 2 bytes more than an ENUM). Read our guide on zero-downtime SQL migration practices to understand table lock levels during constraint changes.
Migration trade-offs: altering ENUMs vs updating constraints
The defining difference between the two approaches emerges when business requirements change.
Adding values
Adding a new value to an ENUM type is relatively straightforward in modern PostgreSQL (version 9.1 and later):
Adding values to an ENUM type
-- Adding a new value to an ENUMALTER TYPE order_status_type ADD VALUE 'returned' AFTER 'shipped';
However, PostgreSQL does not allow a newly added enum value to be used within the same transaction that created it. Furthermore, you cannot add an enum value inside a multi-statement transaction block in certain versions, which can complicate automated ORM migration scripts like Flyway or Liquibase.
Removing or renaming values
PostgreSQL provides no direct ALTER TYPE ... DROP VALUE command. If you want to remove an obsolete status from an ENUM, you must create a new enum type, rewrite the table column using ALTER TABLE ... ALTER COLUMN ... TYPE, and drop the old type. On a table with 50 million rows, rewriting the column requires an exclusive table lock that halts application traffic for minutes or hours.
In contrast, modifying a CHECK constraint never requires rewriting table data. You add a new constraint with NOT VALID, validate it concurrently in the background without exclusive locks, and drop the old constraint instantly:
Zero-downtime CHECK constraint update
-- Step 1: Add updated constraint marked NOT VALID (takes instant lock, scans zero rows)ALTER TABLE customer_orders_checkADD CONSTRAINT chk_valid_order_status_v2CHECK (current_status IN ('draft', 'submitted', 'processing', 'shipped', 'cancelled', 'returned'))NOT VALID;-- Step 2: Validate constraint in background without blocking table writesALTER TABLE customer_orders_checkVALIDATE CONSTRAINT chk_valid_order_status_v2;-- Step 3: Drop outdated constraintALTER TABLE customer_orders_checkDROP CONSTRAINT chk_valid_order_status;
Storage footprint: ENUM is always 4 bytes; VARCHAR is text length plus 1 byte overhead.
Type safety: ENUM prevents invalid values across all tables referencing the type; CHECK constraints must be applied to each table individually.
Drop flexibility: ENUM cannot drop values without table rewrites; CHECK constraints can be modified with zero downtime using NOT VALID.
Portability: CHECK constraints work identically in MySQL, SQLite, and SQL Server; custom ENUM types are PostgreSQL-specific.
Actionable checklist for categorical column design
Assess category volatility: use ENUM only for fixed, permanent sets (cardinal directions, days of week).
Default to VARCHAR with CHECK: use text with CHECK constraints for business statuses that evolve over time.
Use NOT VALID for constraint migrations: add constraints as NOT VALID first and validate concurrently in production.
Place indexes carefully: remember that B-tree index size reflects the 4-byte ENUM or variable-length VARCHAR storage.
Check transaction block restrictions: avoid bundling ALTER TYPE ADD VALUE in multi-statement transaction blocks.
Normalize if attributes expand: convert categorical columns to foreign key lookup tables if statuses require metadata like display names or color codes.
Wrapping up
While PostgreSQL ENUM types offer compact 4-byte storage and catalog-level type safety, VARCHAR columns with CHECK constraints provide far greater agility for evolving business workflows. Choosing the right pattern avoids disruptive table rewrite locks as your application matures. Format your migration scripts and constraint DDL cleanly with sqlfmt or explore our pricing tiers for automated CI linting.