Search code examples
postgresql

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


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 SQL statement for an existing table in Postgres via commandline or SQL statement?


Solution

  • pg_dump -t 'schema-name.table-name' --schema-only database-name
    

    More info - in the manual.