【发布时间】:2016-12-28 21:03:20
【问题描述】:
我正在尝试将数据从架构“nathalia”的名为“m_aduana”的外部表复制到我的架构“publico”和我的表“mae_aduana”。
我需要做一个查询,复制表“m_aduana”中的所有值,避免重复。
我现在得到了类似的东西,但结果给我发送了一个 Insert 0 0,这意味着没有插入任何内容。
insert into publico.mae_aduana(cod_aduana,nom_aduana,des_aduana,cod_aduana1,cod_aduana2,cod_aduana3,est_aduana)
select cod_aduana,nom_aduana,des_aduana,cod_aduana1,cod_aduana2,cod_aduana3,est_aduana
from nathalia.m_aduana
where not exists (
select * from publico.mae_aduana ma_ad, nathalia.m_aduana m_ad
where ma_ad.cod_aduana = m_ad.cod_aduana)
【问题讨论】:
-
更有效的方法是使用
insert ... on conflict do nothing而不是where not exists
标签: sql postgresql foreign-data-wrapper