sql - Transfer Data between databases with postgres -


I need to transfer some data from another database. I old database is called paw1.moviesDB and the new database is paw1 . Each table has a schema

Award (table name) (new DB) ID [PK] serial award

Nomination (name of the table) (old DB) ID [PK] Serial Nomination

I want to copy data from old db to new db

I just wanted to do this exact thing, so I thought I posted the recipe. It assumes that both the databases are on the same server.

First of all, copy the table from old db to new dB (because apparently you can not take data between database). On the command line:

  pg_dump -U postgres -t & lt; Old_table & gt; & Lt; Old_database & gt; | Psql -U postgres -d & lt; New_database & gt;  

Next, give the permissions of the copied table to the user of the new database. Enter into Psql:

  psql -U postgres -d & lt; New_database & gt; Optional Table & lt; Old_table & gt; By owner & lt; New_user & gt; \ Q  

Finally, copy the data from the old table to the new table. Log in as a new user and then:

  INSERT < New_table & gt; (Field 1, Field 2, Field 3) Field 1, Field 2, Field 3 & lt; Old_table & gt; Choose from  

done!


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -