Show the SQL that created a table
Read-only
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Generates the full DDL statement that would recreate the table, including columns, defaults, constraints, indexes, and triggers.
postgresqlddlschemainspect
Parameters
Name of the table to inspect.
Commands
Dump the table DDL without ownership or privilege clauses
pg_dump -t <table_name> --schema-only --no-owner --no-privilegesVerification
pg_dump -t <table_name> --schema-only --no-owner --no-privilegesValid CREATE TABLE and related DDL statements are printed.
Undo
Not undoable
This recipe only reads schema metadata and changes nothing.
Pitfalls
- pg_dump must be installed and available on PATH; on Windows it may require a full PostgreSQL installation.
- The output includes indexes, constraints, and triggers associated with the table.
- Column ordering and formatting may differ from the original CREATE statement.