Model constrained database values
Represent a fixed set of PostgreSQL values such as user roles or workflow states.
Drizzle ORM · Function
pgEnum defines a reusable PostgreSQL enum from a type name and allowed string values. The resulting builder can be used as a table column type and as input to Drizzle's schema-generation integrations.
pgEnum creates a reusable PostgreSQL enum definition from a name and a literal list of allowed values. Calling the returned enum builder for a column applies that database enum type while preserving the value union in TypeScript.
pgEnum(name, values)| Name | Type | Description |
|---|---|---|
name | string | The PostgreSQL enum type name. |
values | string[] | The permitted enum string values. |
A reusable PostgreSQL enum column builder.
import { pgEnum, pgTable, serial } from 'drizzle-orm/pg-core';
export const role = pgEnum('role', ['admin', 'basic']);
export const users = pgTable('users', {
id: serial('id').primaryKey(),
role: role('role').notNull(),
});Defines a PostgreSQL enum named role with two permitted values, then uses it as a column type in the users table.
Represent a fixed set of PostgreSQL values such as user roles or workflow states.
Reuse one enum definition across multiple table columns.
Generate validation for enum selections with Drizzle's Zod integration.
pgEnum is imported from drizzle-orm/pg-core and takes an enum name plus an array of allowed string values. The resulting builder can be called when declaring a PostgreSQL table column.
Follow-up: How can the enum be used with generated validation? The documentation shows passing the enum to createSelectSchema, which produces a schema that parses the declared values.
The first argument supplies the PostgreSQL enum type name, while the second lists its permitted values. For example, pgEnum('roles', ['admin', 'basic']) creates a reusable enum definition.
Follow-up: How would you scope an enum to a PostgreSQL schema? Use the schema-specific enum declaration shown in the schemas documentation rather than the root pgEnum helper.
A pgEnum definition can be consumed by schema-generation integrations. The official example passes roles to createSelectSchema and parses a value constrained to the enum's declared members.
Follow-up: What additional benefit does this provide? It lets validation schemas reflect the Drizzle enum definition instead of duplicating the permitted values manually.
pgTablepgSchemacreateSelectSchemapgView