0
0
DynamoDBquery~20 mins

ADD expression for numeric increment in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DynamoDB ADD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1:30remaining
What is the result of this ADD expression?
Given a DynamoDB item with attribute counter initially set to 5, what will be the value of counter after applying this update expression?

UpdateExpression: "ADD counter :inc"
ExpressionAttributeValues: {":inc": 3}
A3
B53
C8
D5
Attempts:
2 left
💡 Hint
ADD increments the numeric attribute by the given value.
📝 Syntax
intermediate
1:30remaining
Which option is the correct syntax for incrementing a numeric attribute using ADD?
Choose the correct UpdateExpression and ExpressionAttributeValues to increment attribute score by 10 in DynamoDB.
AUpdateExpression: "ADD score :val"; ExpressionAttributeValues: {":val": 10}
BUpdateExpression: "SET score = score + :val"; ExpressionAttributeValues: {":val": 10}
CUpdateExpression: "ADD score + 10"; ExpressionAttributeValues: {}
DUpdateExpression: "ADD score :val"; ExpressionAttributeValues: {":val": "10"}
Attempts:
2 left
💡 Hint
ADD requires a numeric value in ExpressionAttributeValues.
optimization
advanced
2:00remaining
Why is using ADD better than SET for numeric increments in DynamoDB?
Consider two update expressions to increment attribute visits by 1:

1) SET visits = visits + :inc
2) ADD visits :inc

Which statement about their behavior is correct?
ASET is atomic and faster because it uses addition in the expression.
BADD is atomic and faster because it directly increments without reading the current value.
CBoth are equally atomic and perform the same internally.
DADD can only decrement, so SET is better for increments.
Attempts:
2 left
💡 Hint
Think about atomicity and performance of ADD vs SET.
🔧 Debug
advanced
1:30remaining
What error occurs with this ADD expression?
Given this update expression:

UpdateExpression: "ADD total :val"
ExpressionAttributeValues: {":val": "5"}

What error will DynamoDB raise?
ASyntaxError: Invalid UpdateExpression
BNo error, update succeeds
CTypeError: Cannot add string to number
DValidationException: The provided value is not a number
Attempts:
2 left
💡 Hint
Check the data type of the value used with ADD.
🧠 Conceptual
expert
2:00remaining
What happens if the attribute does not exist when using ADD to increment?
If you use the update expression ADD clicks :inc with :inc = 1 on an item that does not have the attribute clicks, what will be the result?
AThe attribute <code>clicks</code> is created with value 1
BThe update fails with a ConditionalCheckFailedException
CThe attribute is created with value 0
DThe attribute remains missing and no change occurs
Attempts:
2 left
💡 Hint
Think about how ADD behaves with missing numeric attributes.