如何在保留原始模式的 Postgres 中将某些表从一个模式复制到另一个模式?
How to copy certain tables from one schema to another within same DB in Postgres keeping the original schema?
我只想在 Postgres 的同一个数据库中将 4 个表从 schema1 复制到 schema2。并希望将表也保留在 schema1 中。知道如何在 pgadmin 和 postgres 控制台中做到这一点吗?
您可以使用 create table ... like
create table schema2.the_table (like schema1.the_table including all);
然后将数据从源插入到目标:
insert into schema2.the_table
select *
from schema1.the_table;
您可以使用 CREATE TABLE AS SELECT。这样你就不需要插入了。 Table 将使用数据创建。
CREATE TABLE schema2.the_table
AS
SELECT * FROM schema1.the_table;
适用于 v12 的简单语法:
CREATE TABLE newSchema.newTable
AS TABLE oldSchema.oldTable;
我只想在 Postgres 的同一个数据库中将 4 个表从 schema1 复制到 schema2。并希望将表也保留在 schema1 中。知道如何在 pgadmin 和 postgres 控制台中做到这一点吗?
您可以使用 create table ... like
create table schema2.the_table (like schema1.the_table including all);
然后将数据从源插入到目标:
insert into schema2.the_table
select *
from schema1.the_table;
您可以使用 CREATE TABLE AS SELECT。这样你就不需要插入了。 Table 将使用数据创建。
CREATE TABLE schema2.the_table
AS
SELECT * FROM schema1.the_table;
适用于 v12 的简单语法:
CREATE TABLE newSchema.newTable
AS TABLE oldSchema.oldTable;