title: h2, update multiple columns from select
body: <p>I have a table with a unique constraint, and I want to do an update without violating the unique constraint, to avoid the exception.</p>
  
  <p>This is simply achievable using the correct condition in the <code>where</code> clause. However, using <code>PreparedStatement</code>, I want to avoid having to set the value twice, one for setting it, and one for checking it.</p>
  
  <p>What I can do:</p>
  
  <pre><code>UPDATE mytable SET
     col1 = ?,
     col2 = ?, --has unique constraint
     col3 = ?
  WHERE
     id = ?
  AND NOT EXISTS (
     SELECT *
     FROM mytable
     WHERE
        col2 = ? AND
        id &lt;&gt; ?
  );
  </code></pre>
  
  <p>Notice that I have to enter the value of <code>col2</code> twice, as I have to do so for the <code>id</code>.</p>
  
  <p>What I want to do is something similar to:</p>
  
  <pre><code>UPDATE mytable SET
     col1 = entry.col1,
     col2 = entry.col2,
     col3 = entry.col3
  FROM
     (SELECT * FROM
        ? AS id,
        ? AS col1,
        ? AS col2,
        ? AS col3
     ) AS entry
  WHERE
     id = entry.id
  AND NOT EXISTS (
     SELECT *
     FROM mytable
     WHERE
       col2 = entry.col2 AND
       id &lt;&gt; entry.id
  );
  </code></pre>