title: ERROR: duplicate key value violates unique constraint in postgres
body: <p>here slo_order_item_id is unique constraint </p>
  
  <pre><code> 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);
  </code></pre>
  
  <p>and I also try </p>
  
  <pre><code>WHERE vss_order_item_id not in (select slo_order_item_id from shb.sale_order);
  </code></pre>
  
  <p>but these both are giving error. </p>
  
  <blockquote>
    <p>ERROR:  duplicate key value violates unique constraint
    "unique_sale_order_slo_order_item_id" DETAIL:  Key
    (slo_order_item_id)=(1027559930) already exists.</p>
  </blockquote>
  
  <p>why this is giving error ?
  which one <code>where condition</code> work fast and why ?</p>