Mike
Mike

Reputation: 379

How to transfer specific columns of a table in one database into another database?

I am using pgAdmin 4 for PostgreSQL. I have two databases A and B each having a table called records. In database A, table records has 3 columns person_id, shop_freq and time, and has about 1000 rows. While in database B, table records has 4 columns person_id, shop_freq, start_time and end_time, and is empty.

I want to transfer the data of columns person_id and shop_freq from database A to their corresponding columns in database B, and then transfer column time of database A to column start_time, and pass random data (for instance about 1 to 2 months after the start time) to the column end_time.

How can I do such a thing in an easy and clean way in pgAdmin itself?

Upvotes: 0

Views: 919

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246033

You can use the COPY statement to export the data to a file on the database server and use COPY with column names to load them into the other database.

To fill the missing column, run an UPDATE statement after the import.

Upvotes: 1

Related Questions