title: How can I update a DynamoDB item's attribute based on a condition?
body: <p>I want to update an item on DynamoDB, but one specific attribute of it should only be changed if it's not NULL in the database:</p>
  <p>Say the current item in the DB looks like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PK</th>
  <th>SK</th>
  <th>attribute1</th>
  <th>attribute2</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>MYPK</td>
  <td>some-id1</td>
  <td>old value</td>
  <td>old stuff</td>
  </tr>
  <tr>
  <td>MYPK</td>
  <td>some-id2</td>
  <td>NULL</td>
  <td>old stuff</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Now locally I set attribute1 to <code>new value</code> and attribute2 to <code>new stuff</code>. What I want to obtain after saving to the database is:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PK</th>
  <th>SK</th>
  <th>attribute1</th>
  <th>attribute2</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>MYPK</td>
  <td>some-id1</td>
  <td><strong><em>old</em> value</strong></td>
  <td><strong>new stuff</strong></td>
  </tr>
  <tr>
  <td>MYPK</td>
  <td>some-id2</td>
  <td><strong><em>new</em> value</strong></td>
  <td><strong>new stuff</strong></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Notice how attribute2 was updated for both, but attribute1 was only updated where it was NULL: elsewhere the existing value was kept.</p>
  <p>I know that if attribute1 is not set at all I can use <code>if_not_exists()</code> in the UpdateExpression to do this, but in my case the attribute is already set.</p>
  <p>Is there any way to do this (for example with some syntax of UpdateExpression) without having to query the database and check the value of attribute1 manually?</p>