I need to copy just the data from a table in one database into another table in another database. The table in the target database has the exact same schema except that the name of the table is different. The two databases are on the same machine.
I can't find a way to pipe the data from pg_dump
into a differently named table in the target database.
Here's the command I would use if the tables were named the exact same:
pg_dump -a -t <table_name> <source_db> | psql <target_db>
But where would I be able to put the name of the target table in the target database?
The reason I'm doing this is because I'm building a Django web-app, and I've realized I really need to separate a bunch of the models I've created into different 'apps' within my Django project.
You could do it with COPY
:
psql -d db1 -c 'COPY table_1 TO STDOUT' | psql -d db2 -c 'COPY table_2 FROM STDIN'