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:

  1. Select the table you want to copy from the list in the left sidebar.
  2. Switch to the Structure tab at the bottom, or use shortcut keys Cmd + Ctrl + ]
  3. Click on the Definition button near the top bar.

Then you will see the table creation statement to copy.

Table Creation Statement


Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS.

TablePlus GUI Tool PostgreSQL