Introduction
The DELETE expression in DynamoDB helps you remove specific items from a set attribute without deleting the whole item.
Jump into concepts and practice - no test required
The DELETE expression in DynamoDB helps you remove specific items from a set attribute without deleting the whole item.
UPDATE table_name SET attribute_name = attribute_name DELETE :values_to_remove WHERE key_condition
The DELETE keyword here is used to remove elements from a set attribute.
:values_to_remove is a placeholder for the set of values you want to remove.
UPDATE Users SET favoriteColors = favoriteColors DELETE :colorsToRemove WHERE userId = :id
UPDATE Products SET tags = tags DELETE :tagsToRemove WHERE productId = :pid
This query removes specific genres from the genres set for the artist with the given artistId.
UPDATE Music SET genres = genres DELETE :removeGenres WHERE artistId = :artistId
The DELETE expression only works on set attributes, not lists or other types.
If the value to remove does not exist in the set, DynamoDB ignores it without error.
Use DELETE expression to remove specific elements from a set attribute.
This helps update parts of your data without replacing the whole set.
DELETE expression do in DynamoDB when used with a set attribute?colors using the DELETE expression in DynamoDB?colors is a set of strings, the value must be a string set (SS), not a single string (S).tags as a string set: {"red", "green", "blue"}, what will be the value of tags after applying this update?UpdateExpression: "DELETE tags :vals"
ExpressionAttributeValues: {":vals": {"SS": ["green", "yellow"]}}fruits but it fails with a syntax error:UpdateExpression: "DELETE fruits :val"
ExpressionAttributeValues: {":val": {"S": "apple"}}fruits is a set, so the value to delete must be a set type (SS), not a single string (S).features as a string set: {"wifi", "pool", "parking", "gym"}. You want to remove "pool" and "spa" from this set using a single update. Which is the correct approach and expected result?