Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql - Dump database with x tables - schema only but data from one table

wondering about a little convenience problem of mine atm.

Say I got a database with a variable amount of tables and I want a dump of that database BUT only the table structure and the data of one specific table.

It is, of course, basically possible to do that, but the command would be rather long and I'd have to know all the tables.

But I'd need a command without knowing the names or how many other tables there are, only the one table whose data I want should be relevant, the others are basically just cattle, and in the end I would like to have it all in one file.

Looking forward to reading some suggestions or maybe some pointers on how to solve my problem. Really curious :)

like image 565
Samarek Avatar asked Jan 24 '17 10:01

Samarek


1 Answers

The default pg_dump output format is a psql script, so you can just concatenate them:

pg_dump -d my_db --schema-only > dump.sql
pg_dump -d my_db -t my_table --data-only >> dump.sql
like image 74
Nick Barnes Avatar answered Sep 17 '22 23:09

Nick Barnes