Vivek Sable
Vivek Sable

Reputation: 10213

Unable to query on Partition key in DyanmoDB by boto3

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

Upvotes: 3

Views: 1862

Answers (1)

F_SO_K
F_SO_K

Reputation: 14799

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

Upvotes: 1

Related Questions