postgresql 如何在保持原始模式的 Postgres 中将某些表从一个模式复制到同一数据库中的另一个模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39890502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to copy certain tables from one schema to another within same DB in Postgres keeping the original schema?
提问by TheCuriousOne
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 ?
我只想在 Postgres 的同一数据库中将 4 个表从 schema1 复制到 schema2。并希望将表保留在 schema1 中。知道如何在 pgadmin 和 postgres 控制台中做到这一点吗?
回答by a_horse_with_no_name
You can use create table ... like
您可以使用 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;
回答by Alec
You can use CREATE TABLE AS SELECT. This ways you do not need to insert. Table will be created with data.
您可以使用 CREATE TABLE AS SELECT。这种方式你不需要插入。将使用数据创建表。
CREATE TABLE schema2.the_table
AS
SELECT * FROM schema1.the_table;