Column metadata and name resolution #
Expressions refer to columns by position, so names never affect evaluation. Names are metadata: a
Column records an optional qualifier (the table name or alias), a name and a declared type, and
the columns of an n-column row are Fin n → Column. Resolving a reference [q.]name against
them (resolveColumn) gives the unique matching position, or unknownColumn when no column
matches, or ambiguousColumn when several do. An unqualified reference matches every column of
that name; a qualified one only columns with that qualifier. Names are compared exactly: a parser
normalizes case before resolution.
These facts are what a translator from surface SQL to positional expressions needs to prove its
output well-scoped: a resolved position matches the reference (resolveColumn_eq_ok_iff), and the
two errors say precisely that nothing or more than one column matches.
It adapts and redesigns the column lookup of sql_equiv (revision 38030a6b) by Evelyn Mitchell,
where rows carried their names and lookup took the first case-insensitive match; here ambiguity is
an error and names are separate from rows.
Main definitions #
Cslib.SQL.Column: a column's qualifier, name and declared type.Cslib.SQL.Column.Matches: a column answers to a reference[q.]name.Cslib.SQL.resolveColumn: name resolution, returning a position or aResolveError.
Main results #
Cslib.SQL.resolveColumn_eq_ok_iff: resolution returns exactly the unique matching position.Cslib.SQL.resolveColumn_eq_unknownColumn_iff,Cslib.SQL.resolveColumn_eq_ambiguousColumn_iff: when resolution fails, and why.
Instances For
Why a column reference does not resolve.
- unknownColumn : ResolveError
No column matches the reference.
- ambiguousColumn : ResolveError
Several columns match the reference.
Instances For
Resolve the reference [q.]name against the columns cols: the position of the only matching
column, unknownColumn if none matches, ambiguousColumn if several do.
Instances For
A resolved reference names its column: the column has the requested name, and the requested qualifier when there is one.
Resolution fails with unknownColumn exactly when no column matches.
Resolution fails with ambiguousColumn exactly when two different columns match.