How to generate the statement CREATE TABLE for an existing table in postgreSQL

0 votes
I have created a table in postgreSQL.

How to get the create table statement for a table that is already existing in Postgres via commandline or SQL statement?
Feb 9, 2022 in Database by Vaani
• 7,070 points
7,901 views

1 answer to this question.

0 votes

Generate table creation statement for an existing table
Use command line tool:

pg_dump -t 'schema_name.table_name' --schema-only database_name
 

Use TablePlus GUI Tool:

Select the table that you want to replicate 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 on the top bar.
You will notice the table creation statement to copy.

pg_dump

pg_dump — extract a PostgreSQL database into a script file or other archive file

pg_dump [connection-option...] [option...] [dbname]

answered Feb 9, 2022 by Neha
• 9,020 points

Related Questions In Database

0 votes
2 answers
0