UPDATE — change items

View .md

Change data two ways, by the shape of the WHERE. Name the complete primary key and it's a native single-item write that runs on the first press. Name anything looser — exactly the shape DynamoDB itself refuses — and it becomes a preview-first set-based write: the first Run shows the affected rows, an unchanged second Run applies them, and every write re-checks its predicate atomically.

Syntax

sql
UPDATE "table"SET attr = value [SET attr2 = value2 …]   -- repeated SET; attr ± number arithmetic[REMOVE attr]                             -- drop an attributeWHERE key predicates [AND conditions][RETURNING ALL OLD * | ALL NEW *]

DynamoDB's native clause forms pass through as-is — repeated SET assignments, REMOVE to drop an attribute, attr ± number arithmetic. RETURNING echoes the item before or after the write (single-statement writes only). Guide: Writes & transactions.

Use cases

Change one attribute on one item Native

The everyday fix — promote a user, stamp the moment it happened.

sql
UPDATE "stage.Users"SET Role = 'admin'SET LastSeen = CURRENT_TIMESTAMPWHERE pk = 'USER#42' AND sk = 'PROFILE'
Executes asUpdateItem · Key: USER#42/PROFILE
  • The WHERE must name the complete primary key — the editor flags anything looser before it runs (it would become a sweep, below).
Increment a counter in place Native

Arithmetic SET compiles to a native UpdateExpression — no read-modify-write race.

sql
UPDATE "stage.Accounts"SET balance = balance - 100WHERE accountId = 'A1'
Executes asUpdateItem · UpdateExpression: SET #balance = #balance - :v
Drop an attribute Native

Remove a field entirely — different from setting it to NULL, which stores an explicit null.

sql
UPDATE "stage.Users"REMOVE LegacyFlagWHERE pk = 'USER#42' AND sk = 'PROFILE'
Executes asUpdateItem · UpdateExpression: REMOVE LegacyFlag
See the item you just changed Native

RETURNING ALL NEW * echoes the item as it stands after the write — no second read.

sql
UPDATE "stage.Users"SET Role = 'admin'WHERE pk = 'USER#42' AND sk = 'PROFILE'RETURNING ALL NEW *
Executes asUpdateItem · ReturnValues: ALL_NEW
  • ALL OLD * returns the pre-write item instead. Not available inside transactions.
Sweep a whole set (preview-first) Scan — read the note

Archive every dormant account. No key in the WHERE, so this runs as a bulk write: the first Run previews the matching rows (capped at 1,000), an unchanged second Run writes them.

sql
UPDATE "stage.Accounts"SET status = 'archived'WHERE status = 'dormant'
Executes asPreview first → one UpdateItem per row, each re-checking status = 'dormant' as a ConditionExpression
  • Per-item, not atomic: if a write fails partway, prior writes stand and the status line reports applied / skipped / planned.
  • A row that changed since the preview is skipped and counted, never blindly overwritten.

Try it

Try it · UPDATESample
Executes asUpdateItem · stage.Users
UpdateItem Key: USER#42/PROFILE · UpdateExpression: SET #Role = :v · ReturnValues: ALL_NEW
A complete-key write — native, single item, first press.
#pkNameRole
1USER#42Ada Okaforadmin
Fetched 1 item in 12ms · 0 RCU · 1 partition

Related: Writes & transactions · INSERT & upserts · DELETE · Transactions.

Was this page helpful?