title: Is there an alternative to SQLs MERGE INTO when need different parameters depending on INSERT or UPDATE?
body: <p>I am looking to optimise speed updating tens of thousands of records being imported from another system.  I am using Array DML and am sending the parameters in batches of 3000.</p>
  
  <p>I am currently doing something like</p>
  
  <pre><code>MERGE INTO &lt;TABLE&gt;
  USING ( SELECT 1 FROM RDB$DATABASE )  &lt;-- This is purely to support the merge syntax
  ON TABLE.KEY = :PARAM1
  WHEN MATCHED AND TABLE.FIELD1&lt;:PARAM2 THEN
  UPDATE SET FIELD1=:PARAM2, FIELD2=:PARAM3
  WHEN NOT MATCHED THEN
  INSERT (FIELD1,FIELD2,FIELD3,FIELD4) VALUES (:PARAM1,:PARAM2,PARAM3,PARAM4)
  </code></pre>
  
  <p>The <code>SELECT 1 FROM RDB$DATABASE</code> is the Firebird v3 way of just selecting the number 1 as I don't use the result but the syntax requires a <code>USING</code> section but this feels a little hacky.</p>
  
  <p>I thought about rewriting this as a script but didn't think it would improve the speed.</p>