simple-sql-parser-0.2.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 with a single quote escaped using ''

IntervalLit

text of interval literal, units of interval precision, e.g. interval 3 days (3)

Fields

ilLiteral :: String

literal text

ilUnits :: String

units

ilPrecision :: Maybe Int

precision

Iden Name

identifier without dots

Star

star, as in select *, t.*, count(*)

App Name [ScalarExpr]

function application (anything that looks like c style function application syntactically)

AggregateApp

aggregate application, which adds distinct or all, and order by, to regular function application

Fields

aggName :: Name

aggregate function name

aggDistinct :: Maybe Duplicates

distinct

aggArgs :: [ScalarExpr]

args

aggOrderBy :: [OrderField]

order by

WindowApp

window application, which adds over (partition by a order by b) to regular function application. Explicit frames are not currently supported

Fields

wnName :: Name

window function name

wnArgs :: [ScalarExpr]

args

wnPartition :: [ScalarExpr]

partition by

wnOrderBy :: [OrderField]

order by

wnFrame :: Maybe Frame

frame clause

BinOp ScalarExpr Name 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 Name ScalarExpr

Prefix unary operators. This is used for symbol operators, keyword operators and multiple keyword operators

PostfixOp Name ScalarExpr

Postfix unary operators. This is used for symbol operators, keyword operators and multiple keyword operators

SpecialOp Name [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

case expression. both flavours supported

Fields

caseTest :: Maybe ScalarExpr

test value

caseWhens :: [([ScalarExpr], ScalarExpr)]

when branches

caseElse :: Maybe ScalarExpr

else value

Parens ScalarExpr 
Cast ScalarExpr TypeName

cast(a as typename)

TypedLit 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 Name Source

Represents an identifier name, which can be quoted or unquoted.

Constructors

Name String 
QName String 

Instances

data TypeName Source

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.

Constructors

Distinct 
All 

data OrderField Source

Represents one field in an order by list.

data Direction Source

The direction for a column in order by.

Constructors

Asc 
Desc 

data NullsOrder Source

Represents 'nulls first' or 'nulls last' in an order by clause.

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)

data Frame Source

Represents the frame clause of a window this can be [range | rows] frame_start or [range | rows] between frame_start and frame_end

Instances

data FrameRows Source

Represents whether a window frame clause is over rows or ranges.

Constructors

FrameRows 
FrameRange 

data FramePos Source

represents the start or end of a frame

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;
  • or the table syntax - 'table t', shorthand for 'select * from t'.

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.

data Alias Source

Represents an alias for a table valued expression, used in with queries and in from alias, e.g. select a from t u, select a from t u(b), with a(c) as select 1, select * from a.

Constructors

Alias Name (Maybe [Name]) 

Instances

From

data TableRef Source

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

Constructors

TRSimple Name

from t

TRJoin TableRef JoinType TableRef (Maybe JoinCondition)

from a join b

TRParens TableRef

from (a)

TRAlias TableRef Alias

from a as b(c,d)

TRQueryExpr QueryExpr

from (query expr)

TRFunction Name [ScalarExpr]

from function(args)

TRLateral TableRef

from lateral t

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 [Name]

using (column list)

JoinNatural

natural join was used