How to view a table's CREATE TABLE statement in PostgreSQL

To get the CREATE TABLE statement of an existing table in PostgreSQL, you can use the command line tool pg_dump:

pg_dump -t '<table_name>' --schema-only <database_name>

Example

pg_dump -t 'users' --schema-only my_database

Get started with DB Pilot

DB Pilot is a Database GUI client and SQL editor for PostgreSQL, MySQL, SQLite, DuckDB & more.