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

Drizzle ORM · Type Alias

PgTable

PgTable is the PostgreSQL-specific table type family used for Drizzle table objects created with pgTable. It is useful when typing helpers that accept PostgreSQL tables, while concrete schemas are declared with PostgreSQL builders.

How it works

PgTable is the PostgreSQL table type family represented by tables created with pgTable. Use it when constraining generic helpers or working with PostgreSQL schema objects, while defining concrete tables through the pgTable builder.

Syntax

PgTable

Key points

  • PgTable is tied to PostgreSQL; choose the database dialect before selecting the corresponding table type and builder.
  • The PostgreSQL table represented by PgTable is part of a TypeScript schema declaration, enabling compile-time modeling of database structure.
  • A PgTable-backed schema can guide later query construction and schema changes because Drizzle treats the declared schema as authoritative.
  • PostgreSQL table declarations use imports from drizzle-orm/pg-core, including pgTable and PostgreSQL column builders.

Common mistakes

  • Do not substitute a generic table type for PgTable: Drizzle has no common table object, so helpers must account for the selected SQL dialect.
  • A PostgreSQL table definition needs at least one column; an empty table declaration is not a valid documented pattern.

Example: Using a PostgreSQL table object

import { integer, pgTable, text } from "drizzle-orm/pg-core";

const users = pgTable("users", {
  id: integer().primaryKey(),
  name: text().notNull(),
});

function acceptTable(table: typeof users) {
  return table;
}

acceptTable(users);

Defines a PostgreSQL table with Drizzle's dialect-specific table builder and passes its inferred table object to a typed function.

When to use it

PostgreSQL schema declarations

Create PostgreSQL schemas in TypeScript with Drizzle's pg-core builders.

Typed table helpers

Constrain a generic utility to accept PostgreSQL table objects.

Schema-driven development

Use declared tables as the basis for queries and migrations.

Interview questions

QWhat is PgTable, and how does it relate to pgTable?

PgTable represents a PostgreSQL table type, while pgTable is the builder used to declare a concrete PostgreSQL table. The table's columns and inferred types come from the object passed to pgTable.

Follow-up: Why not use one shared table type for PostgreSQL and other databases? Drizzle uses dialect-specific table objects, so PostgreSQL tables belong to the PgTable family rather than a universal table abstraction.

QWhen would a generic helper use PgTable?

Use PgTable when a generic function should accept PostgreSQL table objects. Define the actual schema with pgTable, choosing PostgreSQL column builders such as integer and text.

Follow-up: How would you make the helper portable? Introduce a dialect-specific abstraction or separate overloads, because the documentation says there is no common table object.

QWhat constraints apply when defining a PostgreSQL table?

A Drizzle table definition must contain at least one column. PostgreSQL tables are declared with the PostgreSQL-specific pgTable builder rather than a database-neutral table constructor.

Follow-up: What should be checked before accepting a table from another dialect? Its table type and builders must match the intended dialect; a MySQL or SQLite table should not be treated as PgTable.

  • pgTable
  • PgColumn
  • pgSchema
  • PgEnum

Source: Schema - Drizzle ORM. Checked 2026-10-16.