DELETE¶
Description¶
The DELETE FROM statement soft-deletes matching rows from a table. In MemoraDB, a deletion does not erase the row from disk; instead, it appends a tombstone record (deleted = 1) to data.db. The row is excluded from standard queries but remains preserved for historical and temporal inspection.
Syntax¶
(See the Syntax Notation Guide for notation rules).
Basic syntax¶
Full syntax¶
Parameters¶
| Parameter | Description |
|---|---|
<table> |
The target table name. |
WHERE <condition> |
Optional filter condition. If omitted, every active row in the table is deleted. |
Examples¶
1. Delete Specific Row by Primary Key (students)¶
2. Delete with Comparison Condition (students)¶
3. Delete All Rows (students)¶
Expected Output¶
How It Works¶
- Target Selection: The executor scans the current active records (
table->scanLatest()). - WHERE Filtering: If a
WHEREclause is provided, matching records are identified. - Tombstone Append:
- For each target record,
table->deleteRow(pk)is invoked. - A new record is appended to the end of
data.dbwith thedeletedflag set to1. - The new version
{timestamp, offset}is added toHistoryIndex. - Subsequent Query Behavior:
- Standard
SELECT * FROM table;ignores tombstoned records. SELECT * FROM table AS OF <past_date>;will still return the record if it was active at<past_date>.HISTORY table WHERE pk = <val>;displays the complete lifecycle, including the tombstone event.
Errors & Edge Cases¶
| Error Condition | Error Message |
|---|---|
| Table Does Not Exist | No such table: '<table>' |
| Unknown Column in WHERE | Unknown column '<col>' on table '<table>' |
| Primary Key Not Found | If no active rows match the condition, 0 row(s) deleted is returned. |