How to copy certain tables from one schema to another inside the same database in Postgres, keeping the original schema?

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

+4
source share
2 answers

you can use create table ... like

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

Then paste the data from the source to the destination:

insert into schema2.the_table
select * 
from schema1.the_table;
+10
source

You can use CREATE TABLE AS SELECT. You do not need to embed these methods. A table will be created with the data.

CREATE TABLE schema2.the_table
AS 
SELECT * FROM schema1.the_table;
+7
source

Source: https://habr.com/ru/post/1656904/


All Articles