0
0
DynamoDBquery~5 mins

REMOVE expression for deleting attributes in DynamoDB

Choose your learning style9 modes available
Introduction

The REMOVE expression lets you delete one or more attributes from an item in a DynamoDB table. It helps keep your data clean by removing unneeded information.

You want to delete a user's outdated phone number from their profile.
You need to remove a temporary flag attribute after a process finishes.
You want to clear a comment or note field from a record.
You want to delete an attribute that is no longer relevant to your application.
Syntax
DynamoDB
UPDATE table_name
SET attribute_name = value [, attribute_name2 = value2, ...]
-- Note: REMOVE is used in UpdateExpression, not in SQL syntax

The REMOVE clause is part of the UpdateExpression in DynamoDB's UpdateItem operation.

You can remove multiple attributes by listing them separated by commas.

Examples
Removes the attribute 'phoneNumber' from the item.
DynamoDB
UpdateExpression: "REMOVE phoneNumber"
Removes both 'tempFlag' and 'oldNote' attributes from the item.
DynamoDB
UpdateExpression: "REMOVE tempFlag, oldNote"
Sample Program

This command removes the 'phoneNumber' attribute from the user with UserId '123' and returns the updated item.

DynamoDB
aws dynamodb update-item \
  --table-name Users \
  --key '{"UserId": {"S": "123"}}' \
  --update-expression "REMOVE phoneNumber" \
  --return-values ALL_NEW
OutputSuccess
Important Notes

If the attribute does not exist, REMOVE does nothing and does not cause an error.

REMOVE only deletes attributes; it cannot delete entire items.

Summary

REMOVE expression deletes specified attributes from an item.

Use it in UpdateExpression with UpdateItem operation.

It helps keep your data tidy by removing unneeded fields.