Speaking DynamoDB's Language (Expression Attributes)
You've mastered the core operations of Kanto — but before you step into Johto's advanced patterns, you need to speak DynamoDB's language fluently.
Almost every Query, Update, and Condition you'll write from here on leans on two kinds of placeholder: ExpressionAttributeValues for the data you compare or write, and ExpressionAttributeNames for the attribute names themselves. Master these and no expression in Johto can surprise you.
Key takeaways
- Placeholders starting with
:live inExpressionAttributeValuesand stand in for actual data values. - Placeholders starting with
#live inExpressionAttributeNamesand stand in for attribute names. - You must alias a name with
#whenever the attribute's name is a DynamoDB reserved word (likeStatus,Name, orType).
Values: the ':' placeholders
You never paste raw data directly into an expression string. Instead you write a placeholder like :atk and bind the real value separately in ExpressionAttributeValues. DynamoDB substitutes it safely at runtime — this prevents injection-style mistakes and lets DynamoDB infer the correct data type.
The expression references :atk; the actual number 120 is bound on the side. You can change the value without ever editing the expression string. (Attackisn't a reserved word, so it's safe to use directly — more on that next.)
Names: the '#' placeholders & reserved words
DynamoDB reserves hundreds of words — Status, Name, Type, Comment, and many more. If one of your attributes is named after a reserved word, using it directly in an expression throws a validation error.
The fix is an ExpressionAttributeName: a placeholder starting with # that stands in for the attribute name itself.
| Attribute name | Reserved? | How to reference it |
|---|---|---|
| Attack | No | Use directly: SET Attack = :v |
| Status | Yes | Alias it: SET #s = :v |
| Name | Yes | Alias it: #n = :v |
When in doubt, alias the name — using # always works, reserved or not.
Putting them together
Most real expressions use both at once: # for the attribute name and : for its value.
Read it as: “Set the attribute #status (which is really Status) to the value :status (which is "Champion").”
Interactive Challenge
Time to crown Mew the Champion. Mew's record has a Status attribute — but Status is a DynamoDB reserved word, so it can't go straight into the expression. Alias it with a # name placeholder and bind the new value with a : value placeholder.
UpdateExpression: "SET #status = :status", map "#status" to "Status" in ExpressionAttributeNames, and bind :status to "Champion" in ExpressionAttributeValues.Quick Quiz
Your Pokémon item has an attribute named Status — a DynamoDB reserved word. How do you safely set it in an UpdateExpression?
Make your choice to test your understanding. Submit to check, and if it's not quite right you can adjust and try again.