title: DynamoDB transactional insert with multiple conditions (PK/SK attribute_not_exists and SK attribute_exists)
body: <p>I have a table with PK (String) and SK (Integer) - e.g.</p>
  <pre><code>PK_id                   SK_version      Data
  -------------------------------------------------------
  c3d4cfc8-8985-4e5...    1               First version
  c3d4cfc8-8985-4e5...    2               Second version
  </code></pre>
  <p>I can do a conditional insert to ensure we don't overwrite the PK/SK pair using ConditionalExpression (in the GoLang SDK):</p>
  <pre><code>putWriteItem := dynamodb.Put{
      TableName:                           &quot;example_table&quot;,
      Item:                                itemMap,
      ConditionExpression:                 aws.String(&quot;attribute_not_exists(PK_id) AND attribute_not_exists(SK_version)&quot;),
  }
  </code></pre>
  <p>However I would also like to ensure that the SK_version is always consecutive but don't know how to write the expression.  In pseudo-code this is:</p>
  <pre><code>putWriteItem := dynamodb.Put{
      TableName:                           &quot;example_table&quot;,
      Item:                                itemMap,
      ConditionExpression:                 aws.String(&quot;attribute_not_exists(PK_id) AND attribute_not_exists(SK_version) **AND attribute_exists(SK_version = :SK_prev_version)**&quot;),
  }
  </code></pre>
  <p>Can someone advise how I can write this?</p>
  <p>in SQL I'd do something like:</p>
  <pre><code>INSERT INTO example_table (PK_id, SK_version, Data)
  SELECT {pk}, {sk}, {data}
  WHERE NOT EXISTS (
                      SELECT  1 
                      FROM    example_table
                      WHERE   PK_id = {pk}
                         AND  SK_version = {sk}
                   )
     AND EXISTS    (
                      SELECT  1
                      FROM    example_table
                      WHERE   PK_id = {pk}
                         AND  SK_version = {sk} - 1
                   )
  </code></pre>
  <p>Thanks</p>