0
0
DynamoDBquery~5 mins

DELETE expression for set removal in DynamoDB

Choose your learning style9 modes available
Introduction

The DELETE expression in DynamoDB helps you remove specific items from a set attribute without deleting the whole item.

You want to remove a specific tag from a list of tags stored as a set.
You need to update a user's preferences by removing some options from a set.
You want to delete a specific email from a set of email addresses in a record.
Syntax
DynamoDB
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.

Examples
This removes specific colors from the favoriteColors set for the user with userId = :id.
DynamoDB
UPDATE Users
SET favoriteColors = favoriteColors DELETE :colorsToRemove
WHERE userId = :id
This removes certain tags from the tags set for a product.
DynamoDB
UPDATE Products
SET tags = tags DELETE :tagsToRemove
WHERE productId = :pid
Sample Program

This query removes specific genres from the genres set for the artist with the given artistId.

DynamoDB
UPDATE Music
SET genres = genres DELETE :removeGenres
WHERE artistId = :artistId
OutputSuccess
Important Notes

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.

Summary

Use DELETE expression to remove specific elements from a set attribute.

This helps update parts of your data without replacing the whole set.