A database has to forget as well as remember. Today you add DELETE, removing every row of a table that matches a WHERE condition.
Execute a DELETE that removes the rows matching its WHERE predicate and reports how many were removed.
DELETE is the first statement that removes data. Parsing mirrors a SELECT’s
front: DELETE FROM table with an optional WHERE. Execution walks the rows and
keeps the ones the predicate rejects - the survivors become the table’s new row
list - and reports how many were removed. With no WHERE, every row matches, so
the table is emptied.
The implementation is the filter operator from lesson 27 read inverted: instead of
returning the matching rows, you retain the non-matching ones. Reusing the same
predicate evaluator keeps DELETE’s condition exactly as expressive as a query’s.
This is your first taste of mutation; UPDATE next changes rows in place rather
than removing them.
type DeleteStmt struct { Table string; Where Expr }// execute: keep only rows where the predicate is FALSE (or all if no Where)// replace the table's rows with the survivors; return the removed count