postgresqlpgadmin

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


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 ?


Solution

  • 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;