title: Querying a DynamoDb table using a combination of `begins_with` and `between` conditions
body: <p>How can I query a DynamoDb table using a combination of the <code>BETWEEN</code> and <code>BEGINS_WITH</code>?</p>
  <p>A simplified example of my tables partition and sort key looks like this:</p>
  <pre><code>PK    |SK
  my_pk |2022-05-13T08:30:00Z#tag0
  my_pk |2022-05-13T08:45:00Z#tag0
  my_pk |2022-05-13T08:45:00Z#tag1
  my_pk |2022-05-13T08:45:00Z#tag2
  my_pk |2022-05-13T09:00:00Z#tag0
  my_pk |2022-05-13T09:00:00Z#tag1
  </code></pre>
  <p>If my <code>SK</code> didn't include the <code>...#tag</code> postfix I could use a <code>KeyConditionExpression</code> like this:</p>
  <pre><code>&quot;KeyConditionExpression&quot;: &quot;#pk = :pk AND #sk BETWEEN :start AND :end&quot;
  </code></pre>
  <p>where <code>start</code> and <code>end</code> are e.g. <code>2022-05-13T08:45:00Z</code> and <code>2022-05-13T09:00:00Z</code>, respectively, but I am unsure how to do it when the postfix is there.</p>
  <p>Note: I never need to query with the <code>tag</code>, it's just there to ensure that the composite primary key is unique.</p>
  <p>Note2: I am using python and boto3 to execute the query.</p>