General text storage
Store titles, descriptions, message bodies, or other unbounded character data in PostgreSQL.
Drizzle ORM · Function
Drizzle ORM’s PostgreSQL text builder defines a variable-length, unlimited character string column. An optional enum configuration narrows inferred insert and select types but does not validate runtime values.
Use the text column builder in a PostgreSQL table schema when a field stores a variable-length character string. An optional enum configuration narrows the inferred insert and select types to the listed string literals, but it does not validate values at runtime.
text(name?, config?)| Name | Type | Description |
|---|---|---|
name | string | Optional database column name. |
config | { enum?: string[] } | Optional configuration object, including an enum array for type inference. |
A PostgreSQL text column builder.
text stores variable-length character data without a declared maximum length.enum configuration can narrow inferred values to a specified set of string literals.text.import { pgTable, text } from "drizzle-orm/pg-core";
export const posts = pgTable("posts", {
title: text("title").notNull(),
status: text("status", { enum: ["draft", "published"] }),
});Defines PostgreSQL variable-length text columns; the enum option narrows inferred TypeScript insert and select types.
Store titles, descriptions, message bodies, or other unbounded character data in PostgreSQL.
Represent a field with a small known set of string literals in TypeScript.
text builder represent?The PostgreSQL text builder represents a variable-length, unlimited character string. In a schema, call text() or provide the database column name, such as text("title").
Follow-up: How can the inferred type be narrowed? Use text({ enum: ["draft", "published"] }); this constrains inferred insert and select types without adding runtime validation.
enum option affect text columns?Pass an enum array in the builder configuration to infer a union of the listed string literals for inserts and selects. The option is a type-inference aid rather than a database or runtime constraint.
Follow-up: What should enforce invalid values at runtime? Add validation in the application or use a database constraint, because the documented enum option does not perform runtime checks.
The builder can be called without arguments, as text(), or with a column name, as text("text"). The resulting schema maps the field to PostgreSQL's text type.
Follow-up: What SQL type is generated? The documentation's example generates a column declared as text.
pgTablenotNullenum