Generate DDL programmatically on Postgresql

后端 未结 6 1838
陌清茗
陌清茗 2020-12-05 17:34

How can I generate the DDL of a table programmatically on Postgresql? Is there a system query or command to do it? Googling the issue returned no pointers.

6条回答
  •  孤街浪徒
    2020-12-05 18:13

    Use pg_dump with this options:

    pg_dump -U user_name -h host database -s -t table_or_view_names -f table_or_view_names.sql
    

    Description:

    -s or --schema-only : Dump only ddl / the object definitions (schema), without data.
    -t or --table Dump :  Dump only tables (or views or sequences) matching table
    

    Examples:

    -- dump each ddl table that elon build.
    $ pg_dump -U elon -h localhost -s -t spacex -t tesla -t solarcity -t boring > companies.sql
    

    Sorry if out of topic. Just wanna help who googling "psql dump ddl" and got this thread.

提交回复
热议问题