Safe Haskell | Safe-Inferred |
---|
The AST for SQL queries
- data ScalarExpr
- = NumLit String
- | StringLit String
- | IntervalLit String String (Maybe Int)
- | Iden String
- | Iden2 String String
- | Star
- | Star2 String
- | App String [ScalarExpr]
- | AggregateApp String (Maybe Duplicates) [ScalarExpr] [(ScalarExpr, Direction)]
- | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr, Direction)]
- | BinOp ScalarExpr String ScalarExpr
- | PrefixOp String ScalarExpr
- | PostfixOp String ScalarExpr
- | SpecialOp String [ScalarExpr]
- | Case (Maybe ScalarExpr) [(ScalarExpr, ScalarExpr)] (Maybe ScalarExpr)
- | Parens ScalarExpr
- | Cast ScalarExpr TypeName
- | CastOp TypeName String
- | SubQueryExpr SubQueryExprType QueryExpr
- | In Bool ScalarExpr InThing
- data TypeName = TypeName String
- data Duplicates
- data Direction
- data InThing
- = InList [ScalarExpr]
- | InQueryExpr QueryExpr
- data SubQueryExprType
- data QueryExpr
- = Select {
- qeDuplicates :: Duplicates
- qeSelectList :: [(Maybe String, ScalarExpr)]
- qeFrom :: [TableRef]
- qeWhere :: Maybe ScalarExpr
- qeGroupBy :: [ScalarExpr]
- qeHaving :: Maybe ScalarExpr
- qeOrderBy :: [(ScalarExpr, Direction)]
- qeLimit :: Maybe ScalarExpr
- qeOffset :: Maybe ScalarExpr
- | CombineQueryExpr { }
- | With [(String, QueryExpr)] QueryExpr
- = Select {
- makeSelect :: QueryExpr
- data CombineOp
- data Corresponding
- data TableRef
- data JoinType
- data JoinCondition
- = JoinOn ScalarExpr
- | JoinUsing [String]
- | JoinNatural
Scalar expressions
data ScalarExpr Source
Represents a scalar expression
NumLit String | a numeric literal optional decimal point, e+- integral exponent, e.g
|
StringLit String | string literal, currently only basic strings between single quotes without escapes (no single quotes in strings then) |
IntervalLit String String (Maybe Int) | text of interval literal, units of interval precision, e.g. interval 3 days (3) |
Iden String | identifier without dots |
Iden2 String String | identifier with one dot |
Star | star |
Star2 String | star with qualifier, e.g t.* |
App String [ScalarExpr] | function application (anything that looks like c style function application syntactically) |
AggregateApp String (Maybe Duplicates) [ScalarExpr] [(ScalarExpr, Direction)] | aggregate application, which adds distinct or all, and order by, to regular function application |
WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr, Direction)] | window application, which adds over (partition by a order by b) to regular function application. Explicit frames are not currently supported |
BinOp ScalarExpr String ScalarExpr | Infix binary operators. This is used for symbol operators (a + b), keyword operators (a and b) and multiple keyword operators (a is similar to b) |
PrefixOp String ScalarExpr | Prefix unary operators. This is used for symbol operators, keyword operators and multiple keyword operators |
PostfixOp String ScalarExpr | Postfix unary operators. This is used for symbol operators, keyword operators and multiple keyword operators |
SpecialOp String [ScalarExpr] | Used for ternary, mixfix and other non orthodox operators, including the function looking calls which use keywords instead of commas to separate the arguments, e.g. substring(t from 1 to 5) |
Case (Maybe ScalarExpr) [(ScalarExpr, ScalarExpr)] (Maybe ScalarExpr) | case expression. both flavours supported. Multiple condition when branches not currently supported (case when a=4,b=5 then x end) |
Parens ScalarExpr | |
Cast ScalarExpr TypeName | cast(a as typename) |
CastOp TypeName String | prefix 'typed literal', e.g. int '42' |
SubQueryExpr SubQueryExprType QueryExpr | exists, all, any, some subqueries |
In Bool ScalarExpr InThing | in list literal and in subquery, if the bool is false it means not in was used ('a not in (1,2)') |
Represents a type name, used in casts.
data Duplicates Source
represents the Distinct or All keywords, which can be used before a select list, in an aggregate/window function application, or in a query expression set operator
The direction for a column in order by.
Used for 'expr in (scalar expression list)', and 'expr in (subquery)' syntax
data SubQueryExprType Source
A subquery in a scalar expression
Query expressions
Represents a query expression, which can be:
- a regular select;
- a set operator (union, except, intersect);
- a common table expression (with);
- a values expression (not yet supported);
- or the table syntax - 'table t', shorthand for 'select * from t' (not yet supported).
Select | |
| |
CombineQueryExpr | |
| |
With [(String, QueryExpr)] QueryExpr |
helper/'default' value for query exprs to make creating query expr values a little easier
Query expression set operators
data Corresponding Source
Corresponding, an option for the set operators
From
Represents a entry in the csv of tables in the from clause.
The type of a join
data JoinCondition Source
The join condition.
JoinOn ScalarExpr | on expr |
JoinUsing [String] | using (column list) |
JoinNatural | natural join was used |