0
0
DynamoDBquery~20 mins

SET expression for adding/changing in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DynamoDB SET Expression Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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?

SET count = count + :inc, tags = list_append(tags, :newTags)

with ExpressionAttributeValues:
{":inc": 3, ":newTags": ["green"]}
A{"id": "123", "count": 8, "tags": ["green", "blue"]}
B{"id": "123", "count": 3, "tags": ["green"]}
C{"id": "123", "count": 8, "tags": ["blue", "green"]}
D{"id": "123", "count": 5, "tags": ["blue"]}
Attempts:
2 left
💡 Hint
Remember that SET can add numbers and list_append appends to the end of a list.
📝 Syntax
intermediate
1: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.
ASET status = :s, score = score + :inc
BSET status := :s, score += :inc
CSET status = :s; score = score + :inc
DSET status == :s, score = score + :inc
Attempts:
2 left
💡 Hint
Use single equals '=' for assignment and '+' for addition in SET expressions.
optimization
advanced
2: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?
ASET address.city = :city, visits = visits + :one
BSET #addr.#city = :city, visits = visits + :one
CSET address['city'] = :city, visits = visits + :one
DSET address.city := :city, visits += :one
Attempts:
2 left
💡 Hint
Use ExpressionAttributeNames for nested attributes to avoid reserved word conflicts.
🔧 Debug
advanced
2:00remaining
Why does this SET expression cause an error?
Given this UpdateExpression:
SET count = count + :inc, tags = list_append(:newTags, tags)
and ExpressionAttributeValues:
{":inc": 2, ":newTags": ["red"]}
The update fails with a ValidationException. Why?
Alist_append requires the existing list as the first argument, but :newTags is first here.
BThe syntax of list_append is incorrect; it needs three arguments.
CThe ExpressionAttributeValues are missing a value for :tags.
DThe attribute 'count' does not exist, so it cannot be incremented.
Attempts:
2 left
💡 Hint
Check the order of arguments in list_append function.
🧠 Conceptual
expert
2:30remaining
What happens when you use SET to add a new attribute that already exists?
If you run this UpdateExpression:
SET newAttr = if_not_exists(newAttr, :start) + :inc
with ExpressionAttributeValues:
{":start": 0, ":inc": 5}
and the item already has newAttr = 10, what will be the new value of newAttr?
A5
B0
CAn error occurs because newAttr already exists.
D15
Attempts:
2 left
💡 Hint
if_not_exists returns the attribute value if it exists, otherwise the default.