How to copy certain tables from one schema to another within same DB in Postgres keeping the original schema?

MANU picture MANU · Oct 6, 2016 · Viewed 32k times · Source

I want to copy only 4 tables from schema1 to schema2 within same DB in Postgres. And would like to keep the tables in schema1 as well. Any idea how to do that in pgadmin as well as from postgres console ?

Answer

a_horse_with_no_name picture a_horse_with_no_name · Oct 6, 2016

You can use create table ... like

create table schema2.the_table (like schema1.the_table including all);

Then insert the data from the source to the destination:

insert into schema2.the_table
select * 
from schema1.the_table;