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 ?
In SQL Management studio right click the database that has the source table, select Tasks -> Export data. You will be able to set source and destination server and schema, select the tables you wish to copy and you can have the destination schema create the tables that will be exported.
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;
You can use CREATE TABLE AS SELECT. This ways you do not need to insert. Table will be created with data.
CREATE TABLE schema2.the_table AS SELECT * FROM schema1.the_table;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With