hssqlppp-0.3.1: SQL parser and type checker




This module contains the database catalog data types and helper functions.

The catalog data type serves the following purposes:

  • Contains all the catalog information needed to type check against an existing database.
  • A copy of the catalog information from a default template1 database is included - defaultTemplate1Catalog.
  • It is used internally to keep track of updates to the catalog whilst running an annotation process (e.g. so that a select can type check against a create table given in the same source). It is also used to track other identifier types, such as attribute references in select expressions, and argument and variable types inside create function statements.

You can see what kind of stuff is contained in the Catalog type by looking at the CatalogUpdate type.


Data types

data Catalog Source

The main datatype, this holds the catalog and context information to type check against.



data CatalogUpdate Source


CatCreateScalar Type String Bool

add a new scalar type with the name given, also creates an array type automatically

CatCreateDomain Type Type

add a new domain to the catalog

CatCreateComposite String [(String, Type)]

add a new composite type to the catalog

CatCreateCast Type Type CastContext

add a new cast to the catalog

CatCreateTable String [(String, Type)] [(String, Type)]

add a new table to the catalog with the given public and private columns also creates the composite type to go with this table

CatCreateView String [(String, Type)]

add the view to the catalog, using the column names and types supplied

CatCreateFunction FunFlav String [Type] Type Bool

add a new function to the catalog

CatDropFunction Bool String [Type]

drop a function from the catalog

ppCatUpdate :: CatalogUpdate -> StringSource

attempt to show a readable representation of a CatalogUpdate value

bits and pieces

data CastContext Source

Use to note what the flavour of a cast is, i.e. if/when it can be used implicitly.

data CompositeFlavour Source

Used to distinguish between standalone composite types, and automatically generated ones, generated from a table or view respectively.

type CompositeDef = (String, CompositeFlavour, Type, Type)Source

Provides the definition of a composite type. The components are composite (or table or view) name, the flavour of the composite, the types of the composite attributes, and the types of the system columns iff the composite represents a table type (the third and fourth components are always CompositeTypes).

type FunctionPrototype = (String, [Type], Type, Bool)Source

The components are: function (or operator) name, argument types, return type and is variadic.

type DomainDefinition = (Type, Type)Source

The components are domain type, base type (todo: add check constraint).

Catalog values

emptyCatalog :: CatalogSource

Represents an empty catalog. This doesn't contain things like the 'and' operator, defaultCatalog contains these.

defaultCatalog :: CatalogSource

Represents what you probably want to use as a starting point if you are building an catalog from scratch. It contains information on built in function like things that aren't in the PostgreSQL catalog, such as greatest, coalesce, keyword operators like 'and', etc..

Catalog comparison

data CatalogDiff Source

items in first catalog and not second, items in second and not first.


compareCatalogs :: Catalog -> Catalog -> Catalog -> CatalogDiffSource

find differences between two catalogs

ppCatDiff :: CatalogDiff -> StringSource

print a catdiff in a more human readable way than show.


updateCatalog :: Catalog -> [CatalogUpdate] -> Either [TypeError] CatalogSource

Applies a list of CatalogUpdates to an Catalog value to produce a new Catalog value.

operator utils