3

I have one table TestTable and partition Key TestColumn.

Inputs Dates:

from_date= "2017-04-20T16:31:54.451071+00:00"
to_date = "2018-04-20T16:31:54.451071+00:00"

when I use equal query the date then it is working.

key_expr = Key('TestColumn').eq(to_date)
query_resp = table.query(KeyConditionExpression=key_expr)

but when I use between query then is not working.

key_expr = Key('TestColumn').between(from_date, to_date)
query_resp = table.query(KeyConditionExpression=key_expr)

Error: Unknown err_msg while querying dynamodb: An error occurred (ValidationException) when calling the Query operation: Query key condition not supported

Vivek Sable
  • 9,938
  • 3
  • 40
  • 56
  • Possible duplicate of [DynamoDb "Query key condition not supported"](https://stackoverflow.com/questions/46414535/dynamodb-query-key-condition-not-supported) – John May 22 '18 at 07:00

1 Answers1

1

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html

DynamoDB Query will return data from one and only one partition, meaning you have to supply a single partition key in the request.

KeyConditionExpression

The condition that specifies the key value(s) for items to be retrieved by the Query action.

The condition must perform an equality test on a single partition key value.

You can optionally use a BETWEEN operator on a sort key (but you still have to supply a single partition key).

If you use a Scan you can use an ExpressionFilter and use the BETWEEN operator on TestColumn

F_SO_K
  • 13,640
  • 5
  • 54
  • 83