Documentation

CslibFrontier.Languages.SQL.Value

SQL values and NULL #

This module fixes the values a cell of a SQL table can hold. A Value is a non-null value of one of the three column types SqlType.int, SqlType.text and SqlType.bool; integers are unbounded and text is a Lean String. A cell holds a Datum, which is Option Value: none is SQL's NULL, which belongs to every type (Datum.HasType).

It adapts and redesigns material from sql_equiv (revision 38030a6b) by Evelyn Mitchell. There, NULL was a value constructor carrying an optional type, and none : Option Value meant an evaluation error. Here a value is never NULL, NULL is the none of a datum, errors are a separate type (Cslib.SQL.EvalError), and decimals are not part of the fragment.

Main definitions #

The column types of the SQL fragment.

  • int : SqlType

    Unbounded integers.

  • text : SqlType

    Character strings, compared by code points.

  • bool : SqlType

    Booleans.

Instances For
    @[instance_reducible]

    A non-null SQL value. NULL is not a value: it is the none of a Datum.

    Instances For
      def Cslib.SQL.instDecidableEqValue.decEq (x✝ x✝¹ : Value) :
      Decidable (x✝ = x✝¹)
      Instances For
        @[instance_reducible]
        @[instance_reducible]

        The type of a value.

        Instances For

          An integer value is an integer literal.

          A text value is a text literal.

          A boolean value is a boolean literal.

          @[reducible, inline]

          The content of a cell: a value, or none for SQL's NULL.

          It is an abbrev so that Option's constructors, instances (DecidableEq, Repr) and lemmas apply to datums directly. The type does not encode errors: evaluation returns Except EvalError Datum, so a NULL result and a failure stay distinct.

          Instances For

            d.HasType τ: the datum is NULL or a value of type τ. NULL has every type.

            Instances For
              @[instance_reducible]
              @[simp]
              theorem Cslib.SQL.Datum.hasType_some {v : Value} {τ : SqlType} :
              HasType (some v) τ ↔ v.type = τ
              theorem Cslib.SQL.Datum.HasType.unique {d : Datum} {τ τ' : SqlType} (hτ : d.HasType τ) (hτ' : d.HasType τ') (hd : d ≠ none) :
              τ = τ'

              A non-null datum has only its own type.