DynamoDB: Query Incorrect operand type

Question:

I’m attempting to read all values in a DynamoDB table above a certain value. I have the primary partition key set to a Number called Project_ID.
I am running a query to see all values above a certain ID – mostly to test out functionality, however I am getting an error when running the code.

The code:

The output

Answer:

In KeyConditionExpression of Query API, the partition key can have only equality operator. The sort key can have multiple operators.

The condition must perform an equality test on a single partition key
value. The condition can also perform one of several comparison tests
on a single sort key value.

Example (sort key):-

sortKeyName < :sortkeyval – true if the sort key value is less than
:sortkeyval.

sortKeyName <= :sortkeyval – true if the sort key value is less than
or equal to :sortkeyval.

You may need to use Scan (with FilterExpression) or BatchGetItem API if you wanted to get multiple items based on some criteria.

Note:-

Scan API will scan the whole table which is costly and inefficient.

Leave a Reply