Item Updates

Behaves like an upsert, meaning that if the item is not found then it gets created. Recall that PuItem aso behaves the same way !! and if you would like to avoid inserting a new item then you can Optionally use a condition expression that is checked before any update operation is applied to the item.

Update Expression

Update operation requires an Update Expression that specifies the actions to be taken on the item identified by its primary key. Expression is created with clauses. Only restriction is that each clause appears only once in the expression.

update-expression

  • SET, updates the value of an attribute; if attribute does not exist then it is created.

update-set-clause

  • Remove is used for removing one or more attributes from the item.

  • Delete clause applies ONLY to attributes of type SET; it is used for removing elements from attribute that are of type Set

  • Add is overloaded that is the action take for this clause depends on the type of the attribute.

update-add-clause

Key attribute Updates

The Update operation cannot be used for updating the item’s key attribute. Key attribute update for an item requires two calls:

  1. Create a new item with the new key
  2. Delete the item with the old key