我们有一个来自SQL SERVER的数据库遗产,现在新的数据库是一个postgres,我想做一些测试,看看两个表中的内容是否相同,我仍然没有访问过遗留数据库(SQL服务器),我说通过轮询两个表来尝试使用新的postgres数据库并尝试比较数据,在迭代循环中我感到困惑,任何想法都会有所帮助:
require 'pg'
pg_conn = PGconn.connect("localhost", 5432, '', '', "myDB", "userxx", "Zazzz")
all_children = pg_conn.exec("SELECT * from COMPANY;")
all_children2 = pg_conn.exec("SELECT * from COMPANY2;")
all_children.each do |child|
??????
end
谢谢,
答案 0 :(得分:0)
快速而肮脏的方法是对一列进行快速检查,例如公司名称,并通过减去结果数组来比较结果以查看差异:
require 'pg'
pg_conn = PGconn.connect("localhost", 5432, '', '', "myDB", "userxx", "Zazzz")
all_children = pg_conn.exec("SELECT name from COMPANY;")
all_children2 = pg_conn.exec("SELECT name from COMPANY2;")
# first check the count, if it's the same it's probably a good sign
puts all_children.length
puts all_children2.length
# check differences
results = all_children.uniq - all_children2.uniq
results2 = all_children2.uniq - all_children.uniq
对于更复杂的测试,您可以使用github上的科学家宝石:https://github.com/github/scientist
编辑: sql版本?
select * from company left outer join company2 on company.name = company.name2 where company2.name is null;