SQL rows and their types #
A row of an n-column table is Row n := Fin n → Datum: columns are referenced by position,
so a reference to a missing column cannot be written. Rows are written ![d₀, d₁, …], and their
equality is decidable through Mathlib's instance for functions on a Fintype, which the kernel
evaluates: decide compares concrete rows, also rows computed by reindexing.
The type information that expressions are checked against is a typing context
Γ : Fin n → SqlType, and a row conforms to it when every cell is NULL or a value of its
column's type (Row.Conforms).
The row of a join is Fin.append of the two input rows, so the left columns are Fin.castAdd and
the right columns Fin.natAdd; a joined row conforms to the appended context exactly when both
inputs conform (Row.conforms_append_iff).
It adapts and redesigns the rows of sql_equiv (revision 38030a6b) by Evelyn Mitchell, which were
lists of name–value pairs whose schema came from the data; here positions are fixed by the type and
names are separate metadata (Cslib.SQL.Column).
Main definitions #
Cslib.SQL.Row: a row ofndatums.Cslib.SQL.Row.Conforms: a row has the types of a typing context.
Main results #
Cslib.SQL.Row.conforms_append_iff: a joined row conforms exactly when both sides do.
A row of an n-column table, by position. It is an abbrev, so rows are functions: ![…],
Fin.append and Fin.cons build them, and they inherit decidable equality.