这里slo_order_item_id是唯一约束
INSERT INTO shb.sale_order
(
slo_order_item_id,
slo_order_id,
slo_channel,
slo_status,
slo_channel_status,
slo_order_date,
slo_dispatch_by_date,
slo_sku,
slo_quantity,
slo_selling_price,
slo_shipping_charge,
slo_vendor_id
)
SELECT Distinct vss_order_item_id,
vss_order_id,
vss_channel_name,
vss_sale_order_item_status,
vss_sale_order_item_status,
case when is_date(vss_order_date) then vss_order_date::date else null end,
case when is_date(vss_dispatch_date) then vss_dispatch_date::date else null end,
vss_sku,
1,
vss_selling_price,
vss_shipping_charge,
vss_vendor_id
FROM imp.vendor_sale_staging udt
WHERE not exists (select 1 from shb.sale_order where slo_order_item_id = udt.vss_order_item_id);
我也尝试
WHERE vss_order_item_id not in (select slo_order_item_id from shb.sale_order);
但这两个都给出了错误。
错误:重复键值违反了唯一约束 " unique_sale_order_slo_order_item_id"细节:钥匙 (slo_order_item_id)=(1027559930)已经存在。
为什么会出错?
哪一个where condition
工作得很快,为什么?
答案 0 :(得分:2)
您可能在登台表中有重复的值。你可以这样做:
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="${APPENDER_FILE}"/>
如果是这种情况,那么我建议修复登台表。但是,加载某些内容的快速入侵是使用select vss_order_item_id, count(*)
from imp.vendor_sale_staging
group by vss_order_item_id
having count(*) > 1;
而不是distinct on
:
distinct