hssqlppp-0.3.1: SQL parser and type checker




Contains the data types and functions for annotating an ast and working with annotated trees, including the representations of SQL data types.


  • are attached to most of the ast node data types, but not quite all of them;
  • types annotations are attached to most nodes during type checking;
  • type errors are attached to the lowest down node that the type error is detected at;
  • nodes who fail the type check or whose type depends on a node with a type error are given the type TypeCheckFailed;
  • each statement has an additional StatementInfo annotation attached to it;
  • the parser fills in the source position annotation in every annotatable ast node.


typechecking/ annotation functions

typeCheckStatements :: Catalog -> [Statement] -> (Catalog, [Statement])Source

Takes an ast, checks against catalog passed, and adds annotations, including types, type errors, and statement info. Returns the updated catalog as well as the annotated ast.

typeCheckParameterizedStatement :: Catalog -> Statement -> Either String StatementSource

Unfinished version of type check which can type check an individual statement with ? or positional arg placeholders in it. Will error if the statement isn't select, update, insert or delete. For use in type checking embedded parameterized statements. Does all typechecking and annotation that the regular typecheck does.

typeCheckScalarExpr :: Catalog -> ScalarExpr -> ScalarExprSource

Testing utility, mainly used to check an expression for type errors or to get its type.

fixUpIdentifiers :: Catalog -> [Statement] -> [Statement]Source

transform the tree by converting * to explicit lists of columns and adding qualifiers to all column references

addExplicitCasts :: Data a => a -> aSource

Run through a typechecked tree and add in explicit casts where implicit casts are used to typecheck. Does function and operator calls, case result expressions, and string, integer and float literals at the moment, todo: union, array, greatest, least

canonicalizeTypeNames :: Data a => a -> aSource

Convert all the typenames in the ast to canonical form e.g. int -> int4

Annotated tree utils

getStatementAnnotations :: Data a => a -> [Annotation]Source

Run through the ast and return all the annotations attached to a Statement node.