PostgreSQL - How to generate CREATE TABLE query for an existing table?
Generate table creation statement for an existing table
Using command line tool:
pg_dump -t 'schema_name.table_name' --schema-only database_name
Using TablePlus GUI Tool:
- Select the table you want to copy from the list in the left sidebar.
- Switch to the
Structure
tab at the bottom, or use shortcut keys Cmd + Ctrl + ] - Click on the
Definition
button near the top bar.
Then you will see the table creation statement to copy.
Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.