Reputation: 89
I'm trying to insert into another database table that I exported using pg_dump:
pg_dump -U postgres --column-inserts --data-only -t table3 -t table2 -t table 1 > c:/file database
The problem is that the tables exist in the other db and I'm getting many primary key errors.
Any other ways to update the tables? how can I add delete table before insertion in the command line?
Thanks in advance!
Upvotes: 4
Views: 15405
Reputation: 31736
With newer versions of Postgres you can now specify an --exclude-table-data=tablename
flag and it will exclude the table from the dump
Upvotes: 1
Reputation: 89
Ok, maybe I should have clarified more, my goal was to update the one db while keeping not updating the tables there, I thought of updating in the beginning only the tables I wanted but instead(after I encountered the problem I wrote above), I'm thinking the best solution for me was just to exclude using the -T in the console(which I missed on the documentation) , worked fine.
Upvotes: 0
Reputation: 324511
Use pg_dump -Fc
to emit a custom-format dump, then restore with pg_restore --clean
. This will drop the tables and re-create them, rather than deleting from them. It should be obvious, but don't do this if there's anything of value in the database you are restoring to.
Upvotes: 7
Reputation: 324
You could manually do a truncate on the table prior to importing it. I don't think there are any command line options to include a delete of the table. The other alternative might be to drop the database prior to importing the data. You'd naturally have to include the schema then.
Upvotes: 0