UPDATE¶
Description¶
The UPDATE statement modifies column values for existing rows. In MemoraDB's append-only architecture, an update does not overwrite the existing bytes on disk; instead, it creates and appends a new version of each target row with an updated timestamp.
Syntax¶
(See the Syntax Notation Guide for notation rules).
Basic syntax¶
Full syntax¶
Parameters¶
| Parameter | Description |
|---|---|
<table> |
The target table name. |
SET <col> = <v> |
One or more column assignments separated by commas. |
WHERE <condition> |
Optional filter condition. If omitted, every active row in the table is updated. |
[!WARNING] Primary Key Immutability: You cannot update the primary key column. Primary keys serve as the immutable anchor for record version chains. To change a primary key, you must
DELETEthe record andINSERTa new record.
Examples¶
1. Update Specific Row with WHERE (students)¶
2. Update Multiple Columns (students)¶
3. Update Semantic Text Column (documents)¶
UPDATE documents
SET content = "All microservices deployed cleanly to production cluster."
WHERE id = 1;
Expected Output¶
How It Works¶
- Target Identification: The engine scans the latest active rows (
table->scanLatest()) and filters them against theWHEREclause (if provided). - Assignment Validation:
- Validates that all target columns exist in the schema.
- Verifies that no assignment attempts to alter the primary key column.
- Validates each new value against the column's data type and size constraints.
- Append New Version:
- For each matched record, a new
Rowis constructed with the modified values. - If the table contains a
SEMANTICcolumn, a new 384-dimensional embedding is generated via ONNX Runtime. - The new version is appended to the end of
data.db(and.vec). - The in-memory
HistoryIndexregisters the new{timestamp, file_offset}for that primary key.
Errors & Edge Cases¶
| Error Condition | Error Message |
|---|---|
| Updating Primary Key | Cannot UPDATE the primary key column '<col>' (delete and re-insert instead) |
| Unknown Column in SET | Unknown column '<col>' on table '<table>' |
| Unknown Column in WHERE | Unknown column '<col>' on table '<table>' |
| Type Mismatch in Value | Validation failure during assignment parsing. |