Challenge - 5 Problems
DynamoDB SET Expression Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this SET expression update?
Given a DynamoDB item with attributes {"id": "123", "count": 5, "tags": ["blue"]}, what will be the updated item after applying this UpdateExpression?
with ExpressionAttributeValues:
SET count = count + :inc, tags = list_append(tags, :newTags)with ExpressionAttributeValues:
{":inc": 3, ":newTags": ["green"]}Attempts:
2 left
💡 Hint
Remember that SET can add numbers and list_append appends to the end of a list.
✗ Incorrect
The count attribute is increased by 3 (5 + 3 = 8). The tags list appends 'green' to the end, so it becomes ["blue", "green"].
📝 Syntax
intermediate1:30remaining
Which SET expression is syntactically correct for updating multiple attributes?
Choose the correct DynamoDB UpdateExpression to set attribute 'status' to 'active' and increment 'score' by 10.
Attempts:
2 left
💡 Hint
Use single equals '=' for assignment and '+' for addition in SET expressions.
✗ Incorrect
Option A uses correct syntax: '=' for assignment and '+' for addition. Other options use invalid operators or punctuation.
❓ optimization
advanced2:30remaining
Optimizing a SET expression to update nested attributes
You want to update the nested attribute 'address.city' to 'Seattle' and increment 'visits' by 1 in a DynamoDB item. Which UpdateExpression is the most efficient and correct?
Attempts:
2 left
💡 Hint
Use ExpressionAttributeNames for nested attributes to avoid reserved word conflicts.
✗ Incorrect
Option B uses ExpressionAttributeNames (#addr and #city) which is best practice for nested attributes. Option B may fail if 'address' or 'city' are reserved words. Options C and D have invalid syntax.
🔧 Debug
advanced2:00remaining
Why does this SET expression cause an error?
Given this UpdateExpression:
and ExpressionAttributeValues:
The update fails with a ValidationException. Why?
SET count = count + :inc, tags = list_append(:newTags, tags)and ExpressionAttributeValues:
{":inc": 2, ":newTags": ["red"]}The update fails with a ValidationException. Why?
Attempts:
2 left
💡 Hint
Check the order of arguments in list_append function.
✗ Incorrect
list_append(list1, list2) requires the existing list attribute as the first argument. Here, :newTags is first, causing the error.
🧠 Conceptual
expert2:30remaining
What happens when you use SET to add a new attribute that already exists?
If you run this UpdateExpression:
with ExpressionAttributeValues:
and the item already has newAttr = 10, what will be the new value of newAttr?
SET newAttr = if_not_exists(newAttr, :start) + :incwith ExpressionAttributeValues:
{":start": 0, ":inc": 5}and the item already has newAttr = 10, what will be the new value of newAttr?
Attempts:
2 left
💡 Hint
if_not_exists returns the attribute value if it exists, otherwise the default.
✗ Incorrect
Since newAttr exists with value 10, if_not_exists returns 10. Then 10 + 5 = 15 is assigned.