PostgreSQL Table Generator
Design a PostgreSQL table column by column and get SQL that follows current Postgres practice: identity columns instead of SERIAL, UUID keys with gen_random_uuid(), JSONB for JSON, TIMESTAMPTZ for points in time, CHECK constraints for enum values, COMMENT ON statements and a trigger that keeps updated_at current.
- Runs in your browser
- No sign-up
- Free to use
How to use PostgreSQL Table Generator
- Enter the table name and optional schema.
- Add a row per column with type, size, keys and default.
- Choose timestamps, soft delete and foreign key behaviour.
- Copy the CREATE TABLE statement and trigger.
PostgreSQL Table Generator features
Modern keys
GENERATED BY DEFAULT AS IDENTITY or UUID with gen_random_uuid().
Postgres types
JSONB, TIMESTAMPTZ, NUMERIC, BOOLEAN, TEXT, BYTEA.
Enums as CHECK
Allowed values enforced without a separate enum type.
updated_at trigger
A trigger function that sets updated_at on every update.
Comments
COMMENT ON TABLE and COMMENT ON COLUMN statements.
Indexes
Separate CREATE INDEX statements, including for foreign keys.
When to use PostgreSQL Table Generator
- Designing tables for Django, Rails, Prisma or plain SQL projects.
- Creating tables in pgAdmin, DBeaver or psql.
- Moving from MySQL habits to PostgreSQL conventions.
- Documenting a schema with comments.
PostgreSQL Table Generator FAQ
Identity or SERIAL?
Identity columns are the SQL-standard replacement for SERIAL since PostgreSQL 10: permissions and sequences are handled automatically. BY DEFAULT allows inserting explicit ids; ALWAYS forbids it.
TIMESTAMP or TIMESTAMPTZ?
TIMESTAMPTZ stores an absolute point in time and converts to the session time zone; it is the right choice for created_at and similar columns. Plain TIMESTAMP stores wall-clock values without a zone.
Why CHECK instead of CREATE TYPE … AS ENUM?
A CHECK constraint is easy to change with a migration; enum types need ALTER TYPE and cannot easily drop values.
Why is a trigger needed for updated_at?
PostgreSQL has no ON UPDATE CURRENT_TIMESTAMP. A BEFORE UPDATE trigger sets the column whenever a row changes.
Do foreign keys get indexes?
PostgreSQL does not create them automatically. Add them under extra indexes; the advice tells you which foreign keys lack one.
Is anything uploaded?
No. The SQL is generated in your browser.
PostgreSQL table design
PostgreSQL offers more column types and constraint options than most databases, and some of its best practices differ from habits formed with MySQL. This generator encodes those practices so a table designed in a few minutes is ready for production use.
Keys come in two flavours. Integer ids use identity columns, the standard replacement for SERIAL. UUID ids use the built-in gen_random_uuid() function, available without extensions since PostgreSQL 13, which suits distributed systems and ids that must not be guessable.
Types follow Postgres conventions: JSON columns become JSONB, which is stored parsed and can be indexed; timestamps become TIMESTAMPTZ; money uses NUMERIC with an exact precision; and enum-like columns become TEXT with a CHECK constraint listing the allowed values, which is easier to evolve than a separate enum type.
Because PostgreSQL has no ON UPDATE clause for columns, the timestamps option adds a small PL/pgSQL trigger function, set_updated_at, and a BEFORE UPDATE trigger on the table. Comments are written with COMMENT ON, so tools like pgAdmin and psql’s \d+ show them.
Unlike MySQL, PostgreSQL does not index foreign key columns automatically. Deleting a parent row or joining from the parent then scans the child table, so the design advice lists foreign keys without an index, and you can add them in the extra indexes field.