PostgreSQL:合并2个类似的数据库 [英] Postgresql : Merge 2 similar databases

查看:130
本文介绍了PostgreSQL:合并2个类似的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将两个数据库(Database1& Database2)合并到Postgresql中的公共数据库。



Database1



表1



Id p> 1 - a

2 - aa

3 - aaa

4 - aaaa



Database2



Table1



Id值(Id为主键)



2 - bb

5 - bbbbb



我想输出为



OutPutDatabase



Table1



strong> Id值(ID为主键)



1 - a

2 - bb

3 - aaa

4 - aaaa

5 - bbbbb



如何实现?

解决方案

不是我的想法,而是我过去阅读的一个。



源:将表移动到新数据库

  pg_dump -d db1 -t table1 | psql db2 

then psql and do

insert into table2(select * from table1);


I have a requirement of merging two databases (Database1 & Database2) to a common database in Postgresql.

Database1

Table1

Id - Value (Id is Primary key)

1 - a
2 - aa
3 - aaa
4 - aaaa

Database2

Table1

Id Value (Id is Primary key)

2 - bb
5 - bbbbb

I want my output as

OutPutDatabase

Table1

Id Value (Id is Primary key)

1 - a
2 - bb
3 - aaa
4 - aaaa
5 - bbbbb

How can I achieve this?

解决方案

Not my idea, but one I have read in the past.

The source: Move table to new database

pg_dump -d db1 -t table1 |psql db2

then psql and do

insert into table2 (select * from table1);

这篇关于PostgreSQL:合并2个类似的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆