swap order in select lists so the expression comes first then the alias to match the order in the concrete syntax
This commit is contained in:
parent
552d3f5383
commit
7cf5275615
|
@ -1,7 +1,3 @@
|
||||||
TODO:
|
|
||||||
P -> P.Parser
|
|
||||||
swap order in select items
|
|
||||||
|
|
||||||
> {-# LANGUAGE TupleSections #-}
|
> {-# LANGUAGE TupleSections #-}
|
||||||
> -- | This is the module with the parser functions.
|
> -- | This is the module with the parser functions.
|
||||||
> module Language.SQL.SimpleSQL.Parser
|
> module Language.SQL.SimpleSQL.Parser
|
||||||
|
@ -573,11 +569,11 @@ expose the b expression for window frame clause range between
|
||||||
|
|
||||||
== select lists
|
== select lists
|
||||||
|
|
||||||
> selectItem :: Parser (Maybe Name, ValueExpr)
|
> selectItem :: Parser (ValueExpr,Maybe Name)
|
||||||
> selectItem = flip (,) <$> valueExpr <*> optionMaybe (try als)
|
> selectItem = (,) <$> valueExpr <*> optionMaybe (try als)
|
||||||
> where als = optional (try (keyword_ "as")) *> name
|
> where als = optional (try (keyword_ "as")) *> name
|
||||||
|
|
||||||
> selectList :: Parser [(Maybe Name,ValueExpr)]
|
> selectList :: Parser [(ValueExpr,Maybe Name)]
|
||||||
> selectList = commaSep1 selectItem
|
> selectList = commaSep1 selectItem
|
||||||
|
|
||||||
== from
|
== from
|
||||||
|
|
|
@ -213,10 +213,10 @@
|
||||||
> text "as" <+> name nm
|
> text "as" <+> name nm
|
||||||
> <+> maybe empty (parens . commaSep . map name) cols
|
> <+> maybe empty (parens . commaSep . map name) cols
|
||||||
|
|
||||||
> selectList :: [(Maybe Name, ValueExpr)] -> Doc
|
> selectList :: [(ValueExpr,Maybe Name)] -> Doc
|
||||||
> selectList is = commaSep $ map si is
|
> selectList is = commaSep $ map si is
|
||||||
> where
|
> where
|
||||||
> si (al,e) = valueExpr e <+> maybe empty als al
|
> si (e,al) = valueExpr e <+> maybe empty als al
|
||||||
> als al = text "as" <+> name al
|
> als al = text "as" <+> name al
|
||||||
|
|
||||||
> from :: [TableRef] -> Doc
|
> from :: [TableRef] -> Doc
|
||||||
|
|
|
@ -196,8 +196,8 @@
|
||||||
> data QueryExpr
|
> data QueryExpr
|
||||||
> = Select
|
> = Select
|
||||||
> {qeSetQuantifier :: SetQuantifier
|
> {qeSetQuantifier :: SetQuantifier
|
||||||
> ,qeSelectList :: [(Maybe Name,ValueExpr)]
|
> ,qeSelectList :: [(ValueExpr,Maybe Name)]
|
||||||
> -- ^ the column aliases and the expressions
|
> -- ^ the expressions and the column aliases
|
||||||
|
|
||||||
TODO: consider breaking this up. The SQL grammar has
|
TODO: consider breaking this up. The SQL grammar has
|
||||||
queryexpr = select <select list> [<table expression>]
|
queryexpr = select <select list> [<table expression>]
|
||||||
|
|
|
@ -12,7 +12,7 @@ Some tests for parsing full queries.
|
||||||
> fullQueriesTests = Group "queries" $ map (uncurry TestQueryExpr)
|
> fullQueriesTests = Group "queries" $ map (uncurry TestQueryExpr)
|
||||||
> [("select count(*) from t"
|
> [("select count(*) from t"
|
||||||
> ,makeSelect
|
> ,makeSelect
|
||||||
> {qeSelectList = [(Nothing, App "count" [Star])]
|
> {qeSelectList = [(App "count" [Star], Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> }
|
> }
|
||||||
> )
|
> )
|
||||||
|
@ -24,10 +24,10 @@ Some tests for parsing full queries.
|
||||||
> \ having count(1) > 5\n\
|
> \ having count(1) > 5\n\
|
||||||
> \ order by s"
|
> \ order by s"
|
||||||
> ,makeSelect
|
> ,makeSelect
|
||||||
> {qeSelectList = [(Nothing, Iden "a")
|
> {qeSelectList = [(Iden "a", Nothing)
|
||||||
> ,(Just "s"
|
> ,(App "sum" [BinOp (Iden "c")
|
||||||
> ,App "sum" [BinOp (Iden "c")
|
> "+" (Iden "d")]
|
||||||
> "+" (Iden "d")])]
|
> ,Just "s")]
|
||||||
> ,qeFrom = [TRSimple "t", TRSimple "u"]
|
> ,qeFrom = [TRSimple "t", TRSimple "u"]
|
||||||
> ,qeWhere = Just $ BinOp (Iden "a") ">" (NumLit "5")
|
> ,qeWhere = Just $ BinOp (Iden "a") ">" (NumLit "5")
|
||||||
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
|
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
|
||||||
|
|
|
@ -18,16 +18,16 @@ Here are the tests for the group by component of query exprs
|
||||||
> simpleGroupBy :: TestItem
|
> simpleGroupBy :: TestItem
|
||||||
> simpleGroupBy = Group "simpleGroupBy" $ map (uncurry TestQueryExpr)
|
> simpleGroupBy = Group "simpleGroupBy" $ map (uncurry TestQueryExpr)
|
||||||
> [("select a,sum(b) from t group by a"
|
> [("select a,sum(b) from t group by a"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
|
||||||
> ,(Nothing, App "sum" [Iden "b"])]
|
> ,(App "sum" [Iden "b"],Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
|
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
|
||||||
> })
|
> })
|
||||||
|
|
||||||
> ,("select a,b,sum(c) from t group by a,b"
|
> ,("select a,b,sum(c) from t group by a,b"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
|
||||||
> ,(Nothing, Iden "b")
|
> ,(Iden "b",Nothing)
|
||||||
> ,(Nothing, App "sum" [Iden "c"])]
|
> ,(App "sum" [Iden "c"],Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = [SimpleGroup $ Iden "a"
|
> ,qeGroupBy = [SimpleGroup $ Iden "a"
|
||||||
> ,SimpleGroup $ Iden "b"]
|
> ,SimpleGroup $ Iden "b"]
|
||||||
|
@ -49,7 +49,7 @@ sure which sql version they were introduced, 1999 or 2003 I think).
|
||||||
> ,ms [Rollup [SimpleGroup $ Iden "a", SimpleGroup $ Iden "b"]])
|
> ,ms [Rollup [SimpleGroup $ Iden "a", SimpleGroup $ Iden "b"]])
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms g = makeSelect {qeSelectList = [(Nothing,Star)]
|
> ms g = makeSelect {qeSelectList = [(Star,Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = g}
|
> ,qeGroupBy = g}
|
||||||
|
|
||||||
|
|
|
@ -37,45 +37,46 @@ These are a few misc tests which don't fit anywhere else.
|
||||||
> where
|
> where
|
||||||
> ms d = makeSelect
|
> ms d = makeSelect
|
||||||
> {qeSetQuantifier = d
|
> {qeSetQuantifier = d
|
||||||
> ,qeSelectList = [(Nothing,Iden "a")]
|
> ,qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]}
|
> ,qeFrom = [TRSimple "t"]}
|
||||||
|
|
||||||
> selectLists :: TestItem
|
> selectLists :: TestItem
|
||||||
> selectLists = Group "selectLists" $ map (uncurry TestQueryExpr)
|
> selectLists = Group "selectLists" $ map (uncurry TestQueryExpr)
|
||||||
> [("select 1",
|
> [("select 1",
|
||||||
> makeSelect {qeSelectList = [(Nothing,NumLit "1")]})
|
> makeSelect {qeSelectList = [(NumLit "1",Nothing)]})
|
||||||
|
|
||||||
> ,("select a"
|
> ,("select a"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing,Iden "a")]})
|
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]})
|
||||||
|
|
||||||
> ,("select a,b"
|
> ,("select a,b"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing,Iden "a")
|
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
|
||||||
> ,(Nothing,Iden "b")]})
|
> ,(Iden "b",Nothing)]})
|
||||||
|
|
||||||
> ,("select 1+2,3+4"
|
> ,("select 1+2,3+4"
|
||||||
> ,makeSelect {qeSelectList =
|
> ,makeSelect {qeSelectList =
|
||||||
> [(Nothing,BinOp (NumLit "1") "+" (NumLit "2"))
|
> [(BinOp (NumLit "1") "+" (NumLit "2"),Nothing)
|
||||||
> ,(Nothing,BinOp (NumLit "3") "+" (NumLit "4"))]})
|
> ,(BinOp (NumLit "3") "+" (NumLit "4"),Nothing)]})
|
||||||
|
|
||||||
> ,("select a as a, /*comment*/ b as b"
|
> ,("select a as a, /*comment*/ b as b"
|
||||||
> ,makeSelect {qeSelectList = [(Just "a", Iden "a")
|
> ,makeSelect {qeSelectList = [(Iden "a", Just "a")
|
||||||
> ,(Just "b", Iden "b")]})
|
> ,(Iden "b", Just "b")]})
|
||||||
|
|
||||||
> ,("select a a, b b"
|
> ,("select a a, b b"
|
||||||
> ,makeSelect {qeSelectList = [(Just "a", Iden "a")
|
> ,makeSelect {qeSelectList = [(Iden "a", Just "a")
|
||||||
> ,(Just "b", Iden "b")]})
|
> ,(Iden "b", Just "b")]})
|
||||||
|
|
||||||
> ,("select a + b * c"
|
> ,("select a + b * c"
|
||||||
> ,makeSelect {qeSelectList =
|
> ,makeSelect {qeSelectList =
|
||||||
> [(Nothing,BinOp (Iden (Name "a")) (Name "+")
|
> [(BinOp (Iden (Name "a")) (Name "+")
|
||||||
> (BinOp (Iden (Name "b")) (Name "*") (Iden (Name "c"))))]})
|
> (BinOp (Iden (Name "b")) (Name "*") (Iden (Name "c")))
|
||||||
|
> ,Nothing)]})
|
||||||
|
|
||||||
> ]
|
> ]
|
||||||
|
|
||||||
> whereClause :: TestItem
|
> whereClause :: TestItem
|
||||||
> whereClause = Group "whereClause" $ map (uncurry TestQueryExpr)
|
> whereClause = Group "whereClause" $ map (uncurry TestQueryExpr)
|
||||||
> [("select a from t where a = 5"
|
> [("select a from t where a = 5"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit "5")})
|
> ,qeWhere = Just $ BinOp (Iden "a") "=" (NumLit "5")})
|
||||||
> ]
|
> ]
|
||||||
|
@ -83,8 +84,8 @@ These are a few misc tests which don't fit anywhere else.
|
||||||
> having :: TestItem
|
> having :: TestItem
|
||||||
> having = Group "having" $ map (uncurry TestQueryExpr)
|
> having = Group "having" $ map (uncurry TestQueryExpr)
|
||||||
> [("select a,sum(b) from t group by a having sum(b) > 5"
|
> [("select a,sum(b) from t group by a having sum(b) > 5"
|
||||||
> ,makeSelect {qeSelectList = [(Nothing, Iden "a")
|
> ,makeSelect {qeSelectList = [(Iden "a",Nothing)
|
||||||
> ,(Nothing, App "sum" [Iden "b"])]
|
> ,(App "sum" [Iden "b"],Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
|
> ,qeGroupBy = [SimpleGroup $ Iden "a"]
|
||||||
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"])
|
> ,qeHaving = Just $ BinOp (App "sum" [Iden "b"])
|
||||||
|
@ -114,7 +115,7 @@ These are a few misc tests which don't fit anywhere else.
|
||||||
|
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms o = makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
> ms o = makeSelect {qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeOrderBy = o}
|
> ,qeOrderBy = o}
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ These are a few misc tests which don't fit anywhere else.
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms o l = makeSelect
|
> ms o l = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "a")]
|
> {qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> ,qeOffset = o
|
> ,qeOffset = o
|
||||||
> ,qeFetchFirst = l}
|
> ,qeFetchFirst = l}
|
||||||
|
@ -164,10 +165,10 @@ These are a few misc tests which don't fit anywhere else.
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms1 = makeSelect
|
> ms1 = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "a")]
|
> {qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]}
|
> ,qeFrom = [TRSimple "t"]}
|
||||||
> ms2 = makeSelect
|
> ms2 = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "b")]
|
> {qeSelectList = [(Iden "b",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "u"]}
|
> ,qeFrom = [TRSimple "u"]}
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,7 +190,7 @@ These are a few misc tests which don't fit anywhere else.
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms c t = makeSelect
|
> ms c t = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden c)]
|
> {qeSelectList = [(Iden c,Nothing)]
|
||||||
> ,qeFrom = [TRSimple t]}
|
> ,qeFrom = [TRSimple t]}
|
||||||
> ms1 = ms "a" "t"
|
> ms1 = ms "a" "t"
|
||||||
> ms2 = ms "a" "u"
|
> ms2 = ms "a" "u"
|
||||||
|
|
|
@ -15,4 +15,4 @@ query expressions from one string.
|
||||||
> ,(" select 1;select 1; ",[ms,ms])
|
> ,(" select 1;select 1; ",[ms,ms])
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms = makeSelect {qeSelectList = [(Nothing,NumLit "1")]}
|
> ms = makeSelect {qeSelectList = [(NumLit "1",Nothing)]}
|
||||||
|
|
|
@ -100,5 +100,5 @@ these lateral queries make no sense but the syntax is valid
|
||||||
> JCross (TRSimple "v") Nothing])
|
> JCross (TRSimple "v") Nothing])
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms f = makeSelect {qeSelectList = [(Nothing,Iden "a")]
|
> ms f = makeSelect {qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = f}
|
> ,qeFrom = f}
|
||||||
|
|
|
@ -183,7 +183,7 @@ Tests for parsing value expressions
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms = makeSelect
|
> ms = makeSelect
|
||||||
> {qeSelectList = [(Nothing,Iden "a")]
|
> {qeSelectList = [(Iden "a",Nothing)]
|
||||||
> ,qeFrom = [TRSimple "t"]
|
> ,qeFrom = [TRSimple "t"]
|
||||||
> }
|
> }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue