0
0
DynamoDBquery~10 mins

SET expression for adding/changing in DynamoDB - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - SET expression for adding/changing
Start Update Request
Parse SET Expression
Identify Attributes to Add or Change
Apply Changes to Item
Save Updated Item
Return Success or Error
This flow shows how DynamoDB processes a SET expression to add or change attributes in an item during an update.
Execution Sample
DynamoDB
UpdateExpression: "SET Age = Age + :inc, City = :newCity"
ExpressionAttributeValues: {":inc": 1, ":newCity": "Seattle"}
This update adds 1 to the Age attribute and changes City to 'Seattle' in the item.
Execution Table
StepAttributeCurrent ValueOperationValue UsedNew Value
1Age30Add131
2City"New York"Change"Seattle""Seattle"
3Save ItemN/AN/AN/AAge=31, City="Seattle"
4EndN/AN/AN/AUpdate complete
💡 All SET operations applied; item updated successfully.
Variable Tracker
AttributeStartAfter Step 1After Step 2Final
Age30313131
City"New York""New York""Seattle""Seattle"
Key Moments - 2 Insights
Why does Age increase from 30 to 31 instead of being replaced?
Because the SET expression uses 'Age = Age + :inc', it adds the value 1 to the existing Age (30), resulting in 31, as shown in execution_table step 1.
What happens if the attribute does not exist before the update?
DynamoDB creates the attribute with the new value. For example, if City did not exist, it would be added with value 'Seattle' as in step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the value of Age after step 1?
A30
B31
C1
D32
💡 Hint
Check the 'New Value' column for Age at step 1 in the execution_table.
At which step does the City attribute change to 'Seattle'?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the 'Attribute' and 'New Value' columns in execution_table rows.
If the SET expression was only 'SET Age = :newAge' with :newAge = 35, what would be the Age after update?
A35
B31
C30
D36
💡 Hint
Replacing Age sets it directly to the new value, not adding.
Concept Snapshot
SET expression in DynamoDB UpdateItem:
- Use 'SET' to add or change attributes.
- Syntax: SET attr = value or attr = attr + value
- Adds attribute if missing, updates if exists.
- Supports arithmetic for numbers.
- Use ExpressionAttributeValues for values.
Full Transcript
This visual execution shows how DynamoDB processes a SET expression during an update. Starting with an item having Age 30 and City 'New York', the SET expression 'SET Age = Age + :inc, City = :newCity' adds 1 to Age and changes City to 'Seattle'. Step 1 adds 1 to Age, making it 31. Step 2 changes City to 'Seattle'. The updated item is saved with Age 31 and City 'Seattle'. Key points include that adding to an attribute increases its value, and missing attributes are created. The quiz checks understanding of these steps and outcomes.