simple-sql-parser-0.1.0.0: A parser for SQL queries

Safe HaskellSafe-Inferred

Language.SQL.SimpleSQL.Syntax

Contents

Description

The AST for SQL queries

Synopsis

Scalar expressions

data ScalarExpr Source

Represents a scalar expression

Constructors

NumLit String

a numeric literal optional decimal point, e+- integral exponent, e.g

  • 10
  • 10.
  • .1
  • 10.1
  • 1e5
  • 12.34e-6
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)')

data TypeName Source

Represents a type name, used in casts.

Constructors

TypeName String 

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

Constructors

Distinct 
All 

data Direction Source

The direction for a column in order by.

Constructors

Asc 
Desc 

data InThing Source

Used for 'expr in (scalar expression list)', and 'expr in (subquery)' syntax

data SubQueryExprType Source

A subquery in a scalar expression

Constructors

SqExists

exists (query expr)

SqSq

a scalar subquery

SqAll

all (query expr)

SqSome

some (query expr)

SqAny

any (query expr)

Query expressions

data QueryExpr Source

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).

makeSelect :: QueryExprSource

helper/'default' value for query exprs to make creating query expr values a little easier

data CombineOp Source

Query expression set operators

Constructors

Union 
Except 
Intersect 

data Corresponding Source

Corresponding, an option for the set operators

From

data TableRef Source

Represents a entry in the csv of tables in the from clause.

Constructors

TRSimple String

from t

TRJoin TableRef JoinType TableRef (Maybe JoinCondition)

from a join b

TRParens TableRef

from (a)

TRAlias TableRef String (Maybe [String])

from a as b(c,d)

TRQueryExpr QueryExpr

from (query expr)

data JoinType Source

The type of a join

Constructors

JInner 
JLeft 
JRight 
JFull 
JCross 

data JoinCondition Source

The join condition.

Constructors

JoinOn ScalarExpr

on expr

JoinUsing [String]

using (column list)

JoinNatural

natural join was used