Bird
Raised Fist0
DynamoDBquery~20 mins

Expression attribute names in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Expression Attribute Names Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Using Expression Attribute Names to Access Reserved Words

You have a DynamoDB table with an attribute named "Name", which is a reserved word. You want to update the attribute "Name" to "Alice" for the item with "ID" = 123.

Which update expression and expression attribute names will correctly update the item?

DynamoDB
UpdateExpression = "SET #N = :val"
ExpressionAttributeNames = {"#N": "Name"}
ExpressionAttributeValues = {":val": "Alice"}
AUpdateExpression = "SET Name = :val" without ExpressionAttributeNames
BUpdateExpression = "SET #N = :val" with ExpressionAttributeNames = {"#N": "Name"}
CUpdateExpression = "SET #Name = :val" with ExpressionAttributeNames = {"#Name": "Name"}
DUpdateExpression = "SET #N = :val" with ExpressionAttributeNames = {"#Name": "Name"}
Attempts:
2 left
💡 Hint

Reserved words require you to use expression attribute names with a placeholder starting with #.

📝 Syntax
intermediate
2:00remaining
Identify the Syntax Error in Expression Attribute Names Usage

Which option contains a syntax error in the use of expression attribute names in a DynamoDB update expression?

DynamoDB
UpdateExpression = "SET #A = :val"
ExpressionAttributeNames = {"#A": "Age"}
ExpressionAttributeValues = {":val": 30}
AExpressionAttributeNames = {"A": "Age"}
BExpressionAttributeNames = {"#A": "#Age"}
CExpressionAttributeNames = {"#A": "Age"}
DExpressionAttributeNames = {"#Age": "Age"}
Attempts:
2 left
💡 Hint

Expression attribute names must start with a # symbol in the key.

query_result
advanced
2:00remaining
Effect of Incorrect Expression Attribute Names Mapping

You run the following DynamoDB update command:

UpdateExpression = "SET #A = :val"
ExpressionAttributeNames = {"#B": "Age"}
ExpressionAttributeValues = {":val": 25}

What will happen when this command is executed?

AA runtime error occurs because #A is not defined in ExpressionAttributeNames
BThe attribute "Age" will be updated to 25
CThe attribute "#A" will be created and set to 25
DThe update will succeed but no attribute will be changed
Attempts:
2 left
💡 Hint

Check if all placeholders in UpdateExpression are defined in ExpressionAttributeNames.

optimization
advanced
2:00remaining
Optimizing Expression Attribute Names for Multiple Reserved Words

You want to update two reserved word attributes, "Status" and "Order", in a DynamoDB item. Which option uses expression attribute names most efficiently?

A
ExpressionAttributeNames = {"Status": "Status", "Order": "Order"}
UpdateExpression = "SET Status = :s, Order = :o"
B
ExpressionAttributeNames = {"#Status": "Status", "#Order": "Order"}
UpdateExpression = "SET #Status = :s, #Order = :o"
C
ExpressionAttributeNames = {"#S": "Status", "#S": "Order"}
UpdateExpression = "SET #S = :s, #S = :o"
D
ExpressionAttributeNames = {"#S": "Status", "#O": "Order"}
UpdateExpression = "SET #S = :s, #O = :o"
Attempts:
2 left
💡 Hint

Each placeholder must be unique and map to one attribute name.

🔧 Debug
expert
3:00remaining
Debugging a Complex UpdateExpression with Nested Attributes

You want to update a nested attribute "info.Name" in a DynamoDB item. The attribute "Name" is reserved. You write:

UpdateExpression = "SET #info.#N = :val"
ExpressionAttributeNames = {"#info": "info", "#N": "Name"}
ExpressionAttributeValues = {":val": "Bob"}

What will be the result of this update?

AThe attribute #info.#N will be created literally as a string key
BA syntax error occurs due to incorrect use of expression attribute names for nested attributes
CThe nested attribute info.Name will be updated to "Bob" successfully
DA runtime error occurs because nested attribute placeholders are not supported
Attempts:
2 left
💡 Hint

Expression attribute names can be used for nested attributes by prefixing each part.

Practice

(1/5)
1. What is the main purpose of using Expression Attribute Names in DynamoDB queries?
easy
A. To increase read capacity units
B. To encrypt data before storing in DynamoDB
C. To create indexes on tables automatically
D. To safely use reserved words or special characters in attribute names

Solution

  1. Step 1: Understand reserved words in DynamoDB

    DynamoDB has reserved words that cannot be used directly as attribute names in expressions.
  2. Step 2: Role of Expression Attribute Names

    Expression Attribute Names let you replace reserved words or special characters with placeholders starting with # to avoid syntax errors.
  3. Final Answer:

    To safely use reserved words or special characters in attribute names -> Option D
  4. Quick Check:

    Expression Attribute Names = safe reserved word usage [OK]
Hint: Use #name to replace reserved words in expressions [OK]
Common Mistakes:
  • Thinking they encrypt data
  • Confusing with indexes
  • Using them to increase capacity
2. Which of the following is the correct way to use an expression attribute name for the reserved word status in a DynamoDB UpdateExpression?
easy
A. UpdateExpression: SET #st = :val with ExpressionAttributeNames: {"#st": "status"}
B. UpdateExpression: SET status = :val
C. UpdateExpression: SET :st = :val
D. UpdateExpression: SET status# = :val

Solution

  1. Step 1: Identify correct syntax for Expression Attribute Names

    Expression Attribute Names start with # and map to real attribute names in ExpressionAttributeNames dictionary.
  2. Step 2: Match syntax with reserved word usage

    UpdateExpression: SET #st = :val with ExpressionAttributeNames: {"#st": "status"} correctly uses #st as placeholder for "status" and defines it in ExpressionAttributeNames.
  3. Final Answer:

    UpdateExpression: SET #st = :val with ExpressionAttributeNames: {"#st": "status"} -> Option A
  4. Quick Check:

    #placeholder = real name syntax [OK]
Hint: Always prefix attribute names with # in expressions [OK]
Common Mistakes:
  • Using reserved word directly without #
  • Using : instead of # for attribute names
  • Appending # after attribute name
3. Given the following DynamoDB query snippet:
FilterExpression: "#yr = :yearVal"
ExpressionAttributeNames: {"#yr": "year"}
ExpressionAttributeValues: {":yearVal": 2023}

What will this filter expression do?
medium
A. Filter items where attribute 'year' equals 2023
B. Filter items where attribute '#yr' equals 2023
C. Cause a syntax error due to missing # in ExpressionAttributeValues
D. Filter items where attribute 'yearVal' equals 2023

Solution

  1. Step 1: Understand ExpressionAttributeNames mapping

    #yr is a placeholder for the attribute name "year" to avoid reserved word conflicts.
  2. Step 2: Understand FilterExpression logic

    The filter checks if the attribute "year" equals the value 2023 provided by :yearVal.
  3. Final Answer:

    Filter items where attribute 'year' equals 2023 -> Option A
  4. Quick Check:

    #yr = year, :yearVal = 2023 [OK]
Hint: Match #name to real attribute, :value to actual value [OK]
Common Mistakes:
  • Confusing placeholders with actual attribute names
  • Thinking #yr is literal attribute
  • Mixing ExpressionAttributeNames and Values
4. You wrote this DynamoDB update:
UpdateExpression: "SET #nm = :nameVal"
ExpressionAttributeNames: {"#name": "name"}
ExpressionAttributeValues: {":nameVal": "Alice"}

Why does this cause an error?
medium
A. ExpressionAttributeValues key ':nameVal' is invalid
B. ExpressionAttributeNames key '#name' does not match placeholder '#nm' in UpdateExpression
C. UpdateExpression cannot use SET with placeholders
D. Missing reserved word declaration

Solution

  1. Step 1: Compare placeholders in UpdateExpression and ExpressionAttributeNames

    UpdateExpression uses #nm but ExpressionAttributeNames defines #name, causing mismatch.
  2. Step 2: Understand placeholder mapping requirement

    Placeholders must match exactly between expression and attribute names dictionary.
  3. Final Answer:

    ExpressionAttributeNames key '#name' does not match placeholder '#nm' in UpdateExpression -> Option B
  4. Quick Check:

    Placeholder names must match exactly [OK]
Hint: Match #placeholder names exactly in all places [OK]
Common Mistakes:
  • Mismatching placeholder names
  • Assuming :value keys cause error
  • Thinking SET can't use placeholders
5. You want to update the attribute named order (a reserved word) and the attribute order#count (which contains a special character) in a DynamoDB item. Which is the correct way to write the UpdateExpression and ExpressionAttributeNames?
hard
A. UpdateExpression: "SET #ord = :val1, #ord#count = :val2" with ExpressionAttributeNames: {"#ord": "order", "#ord#count": "order#count"}
B. UpdateExpression: "SET order = :val1, order#count = :val2" with no ExpressionAttributeNames
C. UpdateExpression: "SET #o = :val1, #c = :val2" with ExpressionAttributeNames: {"#o": "order", "#c": "order#count"}
D. UpdateExpression: "SET #order = :val1, #order#count = :val2" with ExpressionAttributeNames: {"#order": "order", "#order#count": "order#count"}

Solution

  1. Step 1: Understand reserved words and special characters handling

    Reserved words and special characters must be replaced with placeholders starting with # in expressions.
  2. Step 2: Check placeholder naming rules

    Placeholders cannot contain special characters like #, so #order#count is invalid. Use simple placeholders like #o and #c.
  3. Step 3: Verify ExpressionAttributeNames mapping

    UpdateExpression: "SET #o = :val1, #c = :val2" with ExpressionAttributeNames: {"#o": "order", "#c": "order#count"} correctly maps #o to "order" and #c to "order#count" with valid placeholder names.
  4. Final Answer:

    UpdateExpression: "SET #o = :val1, #c = :val2" with ExpressionAttributeNames: {"#o": "order", "#c": "order#count"} -> Option C
  5. Quick Check:

    Use simple # placeholders, map special names correctly [OK]
Hint: Use simple # placeholders; avoid special chars in placeholder names [OK]
Common Mistakes:
  • Using special characters in placeholder names
  • Not using ExpressionAttributeNames for reserved words
  • Trying to use attribute names directly with special chars