6.2. Evaluation
Cslib.SQL.Query.eval returns the list of result rows or an error. Columns are positions:
.col 1 is emp.dept. Results are rows, which are functions, so they are compared after
Except.toOption by decide.
A WHERE clause keeps a row only when its predicate is TRUE. SQL's logic has a third value,
unknown, and NULL produces it. Here cy's department is NULL, so dept <> 1 is unknown
and the row is dropped although cy is not in department 1.
example : ((Query.select (.binary (.cmp .ne) (.col 1) (.lit (.int 1)))
emp).eval D).toOption = some [] := ⊢ (eval D (select (Expr.binary (BinOp.cmp CmpOp.ne) (Expr.col 1) (Expr.lit (Value.int 1))) emp)).toOption = some []
All goals completed! 🐙
example : ((Query.select (.unary .isNull (.col 1)) emp).eval D).toOption =
some [![some (.text "cy"), none]] := ⊢ (eval D (select (Expr.unary UnOp.isNull (Expr.col 1)) emp)).toOption = some [![some (Value.text "cy"), none]]
All goals completed! 🐙
Evaluation is strict: a predicate or a SELECT list is evaluated on every row, and the first
error fails the whole query. Dividing by zero is an error, not NULL.
example : (Query.project ![.binary (.arith .div) (.col 1) (.lit (.int 0))]
emp).eval D = .error .divisionByZero := rfl