Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Function

text

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.

How it works

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.

Syntax

text(name?, config?)

Parameters

NameTypeDescription
namestringOptional database column name.
config{ enum?: string[] }Optional configuration object, including an enum array for type inference.

Returns

A PostgreSQL text column builder.

Key points

  • PostgreSQL text stores variable-length character data without a declared maximum length.
  • An enum configuration can narrow inferred values to a specified set of string literals.
  • The documented enum example produces a select and insert inference containing the listed literal union and nullability.
  • The PostgreSQL schema maps the Drizzle builder to a database column whose SQL type is text.

Common mistakes

  • The enum configuration affects inferred TypeScript types only; it does not enforce the allowed values when the application runs.

Example: Define PostgreSQL text columns

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.

When to use it

General text storage

Store titles, descriptions, message bodies, or other unbounded character data in PostgreSQL.

Type-narrowed string values

Represent a field with a small known set of string literals in TypeScript.

Interview questions

QWhat does Drizzle's PostgreSQL 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.

QHow does the 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.

QWhat declarations can be used for a text column?

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.

  • pgTable
  • notNull
  • enum

Source: Drizzle ORM - PostgreSQL column types. Checked 2026-10-16.