[英]Copy data from table of one db into table of another db using query (both tables have same structure)
I have two database in the same schema. 我在同一架构中有两个数据库。 My db is in Postgres.
我的数据库是Postgres。 I want to copy data of any table (ie product) of my 1st db into the same table of the 2nd db.
我想将我的第一个数据库的任何表(即产品)的数据复制到第二个数据库的同一个表中。
Is it possible to do so using query? 是否可以使用查询这样做?
不能作为单个SQL命令(至少没有没有dblink),但最简单的方法可能是在两个psql之间使用管道 - 两端使用COPY,一个以CSV格式发送数据另一个收到它。
尝试
insert into db1.table1 select * from db2.table2
It's not possible in vanilla PostgreSQL
installation. 在vanilla
PostgreSQL
安装中不可能。
If you are able to install contrib modules, use dblink : 如果您能够安装contrib模块,请使用dblink :
INSERT
INTO product
SELECT *
FROM dblink
(
'dbname=sourcedb',
'
SELECT *
FROM product
'
) AS p (id INT, column1 INT, column2 TEXT, …)
This should be run in the target database. 这应该在目标数据库中运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.