How to generate the “create table” sql statement for an existing table in postgreSQL

后端 未结 19 2018
花落未央
花落未央 2020-11-28 17:49

I have created a table in postgreSQL. I want to look at the SQL statement used to create the table but cannot figure it out.

How do I get the create table

19条回答
  •  迷失自我
    2020-11-28 18:13

    If you want to do this for various tables at once, you meed to use the -t switch multiple times (took me a while to figure out why comma separated list wasn't working). Also, can be useful to send results to an outfile or pipe to a postgres server on another machine

    pg_dump -t table1 -t table2 database_name --schema-only > dump.sql
    
    pg_dump -t table1 -t table2 database_name --schema-only | psql -h server_name database_name
    

提交回复
热议问题