Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to query for greater than sort key in dynamodb with boto3

I have a dynamodb table with string primary key called name and number sort key age. I want to get the items in the dynamodb table with age younger than 30. I understand that since my filter is on a Key, I can use query instead of scan.

So I tried: response = table.query( KeyConditionExpression=Key('age').lt(decimal.Decimal(30)) ) response

But this returns the response:

ClientError: An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: name

So it looks like i need to provide a partition key for queries? Does this mean I can only make queries for age given a name?

What is the code to do this in boto3?

like image 823
tom q Avatar asked Sep 07 '25 03:09

tom q


1 Answers

Yes, it's true. The query needs the partition key, as it runs on a specific partition only.

You need to use the scan and filter in your use case, but this can be a little expensive depending on the size of your table.

The ideal solution would be to keep track of all your partition keys and do parallel queries on them.

like image 67
Eduardo Bortoluzzi Jr Avatar answered Sep 09 '25 03:09

Eduardo Bortoluzzi Jr