In this article, we will see how to Copy table from one database to another in PostgreSQL. We can copy a table from one database to other using pg_dump tool.
Copy table from one database to another in PostgreSQL:
If table is empty then, run the below command from Linux.
pg_dump -t table_to_copy source_db | psql target_db
If table is non-empty then, run the below command from Linux.
pg_dump -a -t my_table my_db | psql target_db
Example:
pg_dump -t student r2schools | psql postgres