Store variable-length names and email addresses
User profile fields
Drizzle ORM · Function
Drizzle ORM's PostgreSQL varchar builder declares variable-length character columns. Configure an optional character limit or an enum array for narrower inferred TypeScript insert and select types.
varchar creates a PostgreSQL variable-length character column. You may omit its configuration, set a maximum character length with length, or provide enum values so Drizzle infers the insert and select types; enum configuration does not validate runtime values.
varchar(config?)| Name | Type | Description |
|---|---|---|
config | { length?: number; enum?: string[] } | Optional configuration object; supports length for the character limit and enum for inferred insert/select string values. |
A PostgreSQL varchar column builder.
varchar and pgTable from drizzle-orm/pg-core.length in the configuration object to create a bounded varchar column.import { pgTable, varchar } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
name: varchar({ length: 256 }).notNull(),
role: varchar({ enum: ["admin", "member"] }),
});Declares a PostgreSQL table with a length-limited required name and an enum-inferred role column.
User profile fields
Bounded textual attributes
Type-narrowed categorical strings
varchar builder represent?varchar defines a variable-length character string column in PostgreSQL. Its optional length setting limits the stored string to that many characters.
Follow-up: How can the schema infer a literal union for the column? Use enum: ["admin", "member"]; remember this does not add runtime validation.
Call varchar() for an unrestricted column or varchar({ length: 256 }) for a length-limited one. The builder is imported from drizzle-orm/pg-core.
Follow-up: What SQL does the length-limited form correspond to? It produces a PostgreSQL varchar(256) column declaration.
enum option?Pass an enum array in the configuration, such as varchar({ enum: ["admin", "member"] }). Drizzle uses it to infer insert and select types.
Follow-up: Does this protect a database from arbitrary strings? No; the documentation explicitly says the enum configuration does not check runtime values.
pgTabletextcharnotNullunique