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

后端 未结 19 2079
花落未央
花落未央 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:03

    Generate the create table statement for a table in postgresql from linux commandline:

    This statement outputs the table create sql statement for me:

    pg_dump -U your_db_user_name your_database -t your_table_name --schema-only
    

    Explanation:

    pg_dump helps us get information about the database itself. -U stands for username. My pgadmin user has no password set, so I don't have to put in a password. The -t option means specify for one table. --schema-only means print only data about the table, and not the data in the table. Here is the exact command I use:

    pg_dump -U pgadmin kurz_prod -t fact_stock_info --schema-only
    

提交回复
热议问题