-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A parser for SQL queries -- -- A parser for SQL queries. Please see the homepage for more information -- http://jakewheat.github.io/simple-sql-parser/. @package simple-sql-parser @version 0.3.1 -- | The AST for SQL queries. module Language.SQL.SimpleSQL.Syntax -- | Represents a value expression. This is used for the expressions in -- select lists. It is also used for expressions in where, group by, -- having, order by and so on. data ValueExpr -- | a numeric literal optional decimal point, e+- integral exponent, e.g -- -- NumLit :: String -> ValueExpr -- | string literal, currently only basic strings between single quotes -- with a single quote escaped using '' StringLit :: String -> ValueExpr -- | text of interval literal, units of interval precision, e.g. interval 3 -- days (3) IntervalLit :: String -> String -> Maybe Int -> ValueExpr -- | literal text ilLiteral :: ValueExpr -> String -- | units ilUnits :: ValueExpr -> String -- | precision ilPrecision :: ValueExpr -> Maybe Int -- | identifier without dots Iden :: Name -> ValueExpr -- | star, as in select *, t.*, count(*) Star :: ValueExpr -- | function application (anything that looks like c style function -- application syntactically) App :: Name -> [ValueExpr] -> ValueExpr -- | aggregate application, which adds distinct or all, and order by, to -- regular function application AggregateApp :: Name -> Maybe SetQuantifier -> [ValueExpr] -> [SortSpec] -> ValueExpr -- | aggregate function name aggName :: ValueExpr -> Name -- | distinct aggDistinct :: ValueExpr -> Maybe SetQuantifier -- | args aggArgs :: ValueExpr -> [ValueExpr] -- | order by aggOrderBy :: ValueExpr -> [SortSpec] -- | window application, which adds over (partition by a order by b) to -- regular function application. Explicit frames are not currently -- supported WindowApp :: Name -> [ValueExpr] -> [ValueExpr] -> [SortSpec] -> Maybe Frame -> ValueExpr -- | window function name wnName :: ValueExpr -> Name -- | args wnArgs :: ValueExpr -> [ValueExpr] -- | partition by wnPartition :: ValueExpr -> [ValueExpr] -- | order by wnOrderBy :: ValueExpr -> [SortSpec] -- | frame clause wnFrame :: ValueExpr -> Maybe Frame -- | 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) BinOp :: ValueExpr -> Name -> ValueExpr -> ValueExpr -- | Prefix unary operators. This is used for symbol operators, keyword -- operators and multiple keyword operators. PrefixOp :: Name -> ValueExpr -> ValueExpr -- | Postfix unary operators. This is used for symbol operators, keyword -- operators and multiple keyword operators. PostfixOp :: Name -> ValueExpr -> ValueExpr -- | Used for ternary, mixfix and other non orthodox operators. Currently -- used for row constructors, and for between. SpecialOp :: Name -> [ValueExpr] -> ValueExpr -- | Used for the operators which look like functions except the arguments -- are separated by keywords instead of commas. The maybe is for the -- first unnamed argument if it is present, and the list is for the -- keyword argument pairs. SpecialOpK :: Name -> (Maybe ValueExpr) -> [(String, ValueExpr)] -> ValueExpr -- | case expression. both flavours supported Case :: Maybe ValueExpr -> [([ValueExpr], ValueExpr)] -> Maybe ValueExpr -> ValueExpr -- | test value caseTest :: ValueExpr -> Maybe ValueExpr -- | when branches caseWhens :: ValueExpr -> [([ValueExpr], ValueExpr)] -- | else value caseElse :: ValueExpr -> Maybe ValueExpr Parens :: ValueExpr -> ValueExpr -- | cast(a as typename) Cast :: ValueExpr -> TypeName -> ValueExpr -- | prefix 'typed literal', e.g. int '42' TypedLit :: TypeName -> String -> ValueExpr -- | exists, all, any, some subqueries SubQueryExpr :: SubQueryExprType -> QueryExpr -> ValueExpr -- | in list literal and in subquery, if the bool is false it means not in -- was used ('a not in (1,2)') In :: Bool -> ValueExpr -> InPredValue -> ValueExpr -- | Represents a ? in a parameterized query Parameter :: ValueExpr -- | Represents an identifier name, which can be quoted or unquoted. data Name Name :: String -> Name QName :: String -> Name -- | Represents a type name, used in casts. data TypeName TypeName :: String -> TypeName PrecTypeName :: String -> Int -> TypeName PrecScaleTypeName :: String -> Int -> Int -> TypeName -- | 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. data SetQuantifier Distinct :: SetQuantifier All :: SetQuantifier -- | Represents one field in an order by list. data SortSpec SortSpec :: ValueExpr -> Direction -> NullsOrder -> SortSpec -- | The direction for a column in order by. data Direction Asc :: Direction Desc :: Direction -- | Represents 'nulls first' or 'nulls last' in an order by clause. data NullsOrder NullsOrderDefault :: NullsOrder NullsFirst :: NullsOrder NullsLast :: NullsOrder -- | Used for 'expr in (value expression list)', and 'expr in (subquery)' -- syntax. data InPredValue InList :: [ValueExpr] -> InPredValue InQueryExpr :: QueryExpr -> InPredValue -- | A subquery in a value expression. data SubQueryExprType -- | exists (query expr) SqExists :: SubQueryExprType -- | a scalar subquery SqSq :: SubQueryExprType -- | all (query expr) SqAll :: SubQueryExprType -- | some (query expr) SqSome :: SubQueryExprType -- | any (query expr) SqAny :: SubQueryExprType -- | Represents the frame clause of a window this can be [range | rows] -- frame_start or [range | rows] between frame_start and frame_end data Frame FrameFrom :: FrameRows -> FramePos -> Frame FrameBetween :: FrameRows -> FramePos -> FramePos -> Frame -- | Represents whether a window frame clause is over rows or ranges. data FrameRows FrameRows :: FrameRows FrameRange :: FrameRows -- | represents the start or end of a frame data FramePos UnboundedPreceding :: FramePos Preceding :: ValueExpr -> FramePos Current :: FramePos Following :: ValueExpr -> FramePos UnboundedFollowing :: FramePos -- | Represents a query expression, which can be: -- -- data QueryExpr Select :: SetQuantifier -> [(ValueExpr, Maybe Name)] -> [TableRef] -> Maybe ValueExpr -> [GroupingExpr] -> Maybe ValueExpr -> [SortSpec] -> Maybe ValueExpr -> Maybe ValueExpr -> QueryExpr qeSetQuantifier :: QueryExpr -> SetQuantifier -- | the expressions and the column aliases qeSelectList :: QueryExpr -> [(ValueExpr, Maybe Name)] qeFrom :: QueryExpr -> [TableRef] qeWhere :: QueryExpr -> Maybe ValueExpr qeGroupBy :: QueryExpr -> [GroupingExpr] qeHaving :: QueryExpr -> Maybe ValueExpr qeOrderBy :: QueryExpr -> [SortSpec] qeOffset :: QueryExpr -> Maybe ValueExpr qeFetchFirst :: QueryExpr -> Maybe ValueExpr CombineQueryExpr :: QueryExpr -> CombineOp -> SetQuantifier -> Corresponding -> QueryExpr -> QueryExpr qe0 :: QueryExpr -> QueryExpr qeCombOp :: QueryExpr -> CombineOp qeSetQuantifier :: QueryExpr -> SetQuantifier qeCorresponding :: QueryExpr -> Corresponding qe1 :: QueryExpr -> QueryExpr With :: Bool -> [(Alias, QueryExpr)] -> QueryExpr -> QueryExpr qeWithRecursive :: QueryExpr -> Bool qeViews :: QueryExpr -> [(Alias, QueryExpr)] qeQueryExpression :: QueryExpr -> QueryExpr Values :: [[ValueExpr]] -> QueryExpr Table :: Name -> QueryExpr -- | Helper/'default' value for query exprs to make creating query expr -- values a little easier. It is defined like this: -- --
--   makeSelect :: QueryExpr
--   makeSelect = Select {qeSetQuantifier = All
--                       ,qeSelectList = []
--                       ,qeFrom = []
--                       ,qeWhere = Nothing
--                       ,qeGroupBy = []
--                       ,qeHaving = Nothing
--                       ,qeOrderBy = []
--                       ,qeOffset = Nothing
--                       ,qeFetchFirst = Nothing}
--   
makeSelect :: QueryExpr -- | Query expression set operators. data CombineOp Union :: CombineOp Except :: CombineOp Intersect :: CombineOp -- | Corresponding, an option for the set operators. data Corresponding Corresponding :: Corresponding Respectively :: Corresponding -- | 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. data Alias Alias :: Name -> (Maybe [Name]) -> Alias -- | Represents an item in a group by clause. data GroupingExpr GroupingParens :: [GroupingExpr] -> GroupingExpr Cube :: [GroupingExpr] -> GroupingExpr Rollup :: [GroupingExpr] -> GroupingExpr GroupingSets :: [GroupingExpr] -> GroupingExpr SimpleGroup :: ValueExpr -> GroupingExpr -- | Represents a entry in the csv of tables in the from clause. data TableRef -- | from t TRSimple :: Name -> TableRef -- | from a join b TRJoin :: TableRef -> JoinType -> TableRef -> (Maybe JoinCondition) -> TableRef -- | from (a) TRParens :: TableRef -> TableRef -- | from a as b(c,d) TRAlias :: TableRef -> Alias -> TableRef -- | from (query expr) TRQueryExpr :: QueryExpr -> TableRef -- | from function(args) TRFunction :: Name -> [ValueExpr] -> TableRef -- | from lateral t TRLateral :: TableRef -> TableRef -- | The type of a join. data JoinType JInner :: JoinType JLeft :: JoinType JRight :: JoinType JFull :: JoinType JCross :: JoinType -- | The join condition. data JoinCondition -- | on expr JoinOn :: ValueExpr -> JoinCondition -- | using (column list) JoinUsing :: [Name] -> JoinCondition -- | natural join was used JoinNatural :: JoinCondition instance Eq Name instance Show Name instance Read Name instance Eq TypeName instance Show TypeName instance Read TypeName instance Eq SubQueryExprType instance Show SubQueryExprType instance Read SubQueryExprType instance Eq NullsOrder instance Show NullsOrder instance Read NullsOrder instance Eq FrameRows instance Show FrameRows instance Read FrameRows instance Eq SetQuantifier instance Show SetQuantifier instance Read SetQuantifier instance Eq Direction instance Show Direction instance Read Direction instance Eq CombineOp instance Show CombineOp instance Read CombineOp instance Eq Corresponding instance Show Corresponding instance Read Corresponding instance Eq Alias instance Show Alias instance Read Alias instance Eq JoinType instance Show JoinType instance Read JoinType instance Eq JoinCondition instance Show JoinCondition instance Read JoinCondition instance Eq ValueExpr instance Show ValueExpr instance Read ValueExpr instance Eq QueryExpr instance Show QueryExpr instance Read QueryExpr instance Eq TableRef instance Show TableRef instance Read TableRef instance Eq GroupingExpr instance Show GroupingExpr instance Read GroupingExpr instance Eq SortSpec instance Show SortSpec instance Read SortSpec instance Eq Frame instance Show Frame instance Read Frame instance Eq FramePos instance Show FramePos instance Read FramePos instance Eq InPredValue instance Show InPredValue instance Read InPredValue -- | This is the module with the parser functions. module Language.SQL.SimpleSQL.Parser -- | Parses a query expr, trailing semicolon optional. parseQueryExpr :: FilePath -> Maybe (Int, Int) -> String -> Either ParseError QueryExpr -- | Parses a value expression. parseValueExpr :: FilePath -> Maybe (Int, Int) -> String -> Either ParseError ValueExpr -- | Parses a list of query expressions, with semi colons between them. The -- final semicolon is optional. parseQueryExprs :: FilePath -> Maybe (Int, Int) -> String -> Either ParseError [QueryExpr] -- | Type to represent parse errors. data ParseError ParseError :: String -> FilePath -> (Int, Int) -> String -> ParseError -- | contains the error message peErrorString :: ParseError -> String -- | filename location for the error peFilename :: ParseError -> FilePath -- | line number and column number location for the error pePosition :: ParseError -> (Int, Int) -- | formatted error with the position, error message and source context peFormattedError :: ParseError -> String instance Eq ParseError instance Show ParseError -- | These is the pretty printing functions, which produce SQL source from -- ASTs. The code attempts to format the output in a readable way. module Language.SQL.SimpleSQL.Pretty -- | Convert a query expr ast to concrete syntax. prettyQueryExpr :: QueryExpr -> String -- | Convert a value expr ast to concrete syntax. prettyValueExpr :: ValueExpr -> String -- | Convert a list of query exprs to concrete syntax. A semi colon is -- inserted after each query expr. prettyQueryExprs :: [QueryExpr] -> String