title: Query a table with primary key and two conditions on sort key
body: <p>I'm trying to query a dynamodb table using the partition key and a sort key.  The sort key is a unix date, so I want to request x partition key between these 2 dates on the sort.  I am currently able to achieve this with a table scan, but I have to move this to a query for the speed benefit.  I am unable to find any decent examples online of people using a partition key and sort key to query their table.</p>
  
  <p>I have carefully read through this <a href="https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/#DynamoDB.Query" rel="noreferrer">https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/#DynamoDB.Query</a> and understand that my params must go within the KeyConditionExpression.</p>
  
  <p>I have read through <a href="https://github.com/aws/aws-sdk-go/blob/master/service/dynamodb/expression/examples_test.go" rel="noreferrer">https://github.com/aws/aws-sdk-go/blob/master/service/dynamodb/expression/examples_test.go</a> and understand it on the whole.  But I just can't find the syntax for KeyConditionExpression</p>
  
  <p>I'd have thought it was something like this:</p>
  
  <pre><code>keyCond := expression.Key("accountId").
      Equal(expression.Value(accountId)).
      And(expression.Key("sortKey").
      Between(expression.Value(fromDateDec), expression.Value(toDateDec)))
  </code></pre>
  
  <p>But this throws:</p>
  
  <blockquote>
    <p>ValidationException: Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: BETWEEN, operand type: NULL</p>
  </blockquote>