title: db2 merge seems to fail on correct where clause
body: <p>I need to merge data from one table to another.</p>
  
  <p>The data is delivered via flat files. That is why I use a load table first before moving it into production. </p>
  
  <p>I add a field <code>loadtabletime</code> to the loadtables, so I can tell db2 only to merge one file at a time, even if more than one file is inserted in the load table at one time. </p>
  
  <p>The load table is <code>loaddlp.reservation_insert</code>, and the production table is <code>dlp.reservation</code>.</p>
  
  <p>This is my query:</p>
  
  <pre><code>MERGE INTO DLP.RESERVATION AS E 
  USING LOADDLP.RESERVATION_INSERT as et 
     on e.TICKET_SERVER = et.TICKET_SERVER 
    and e.RES_ID = et.RES_ID 
    and et.LOADTABLETIME = '2012-06-09 10:44:17.42236' 
   WHEN MATCHED THEN UPDATE SET (foo) = (bar) 
   WHEN NOT MATCHED THEN INSERT (xyz) VALUES (;akdjf)
  </code></pre>
  
  <p>the primary key for load table is <code>ticket_server</code>, <code>res_id</code> and <code>loadtabletime</code>; for prod table it's <code>ticket_server</code> and <code>res_id</code>.</p>
  
  <p>This query fails with the following error:</p>
  
  <blockquote>
    <p>Could not Update data from the stage to production table RESERVATION.
    [[23505] [IBM][CLI Driver][DB2/LINUXX8664] SQL0803N  One or more
    values in the INSERT statement, UPDATE statement, or foreign key
    update caused by a DELETE statement are not valid because the primary
    key, unique constraint or unique index identified by "1" constrains
    table "DLP.RESERVATION" from having duplicate values for the index
    key.  SQLSTATE=23505</p>
  </blockquote>
  
  <p>But, when I remove <code>loadtabletime</code> from the <code>where</code> clause it magically works. Of course, this is not an option as when multiple files are loaded into the load table, you could have pk violations on insert. </p>
  
  <p>When I run:</p>
  
  <pre><code>SELECT count(*) 
    from loaddlp.reservation_insert 
   where LOADTABLETIME = '2012-06-09 10:44:17.42236';
  </code></pre>
  
  <p>I get the correct results. </p>
  
  <p>Does anyone has an idea of what's wrong with the query?</p>