Postgresql でテーブルの DDL をプログラムで生成するにはどうすればよいでしょうか? それを実行するためのシステム クエリまたはコマンドはありますか? この問題について Google で検索しても、ヒントは返されませんでした。
ベストアンサー1
pg_dump
このオプションを使用します:
pg_dump -U user_name -h host database -s -t table_or_view_names -f table_or_view_names.sql
説明:
-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
例:
-- dump each ddl table elon build.
$ pg_dump -U elon -h localhost -s -t spacex -t tesla -t solarcity -t boring > companies.sql