add support for union all and union corresponding and for intersect and except
This commit is contained in:
parent
1199342477
commit
9c4719bda3
|
@ -530,9 +530,13 @@ attempt to fix the precedence and associativity. Doesn't work
|
||||||
> queryExprSuffix qe =
|
> queryExprSuffix qe =
|
||||||
> choice [CombineQueryExpr qe
|
> choice [CombineQueryExpr qe
|
||||||
> <$> try (choice
|
> <$> try (choice
|
||||||
> [Union <$ keyword "union"
|
> [Union <$ keyword_ "union"
|
||||||
> ,Intersect <$ keyword "intersect"
|
> ,Intersect <$ keyword_ "intersect"
|
||||||
> ,Except <$ keyword "except"])
|
> ,Except <$ keyword_ "except"])
|
||||||
|
> <*> (fromMaybe All <$> duplicates)
|
||||||
|
> <*> (option Respectively
|
||||||
|
> $ try (Corresponding
|
||||||
|
> <$ keyword_ "corresponding"))
|
||||||
> <*> queryExpr
|
> <*> queryExpr
|
||||||
> ,return qe]
|
> ,return qe]
|
||||||
|
|
||||||
|
|
|
@ -119,12 +119,18 @@ back into SQL source text. It attempts to format the output nicely.
|
||||||
> ,maybeScalarExpr "limit" lm
|
> ,maybeScalarExpr "limit" lm
|
||||||
> ,maybeScalarExpr "offset" off
|
> ,maybeScalarExpr "offset" off
|
||||||
> ]
|
> ]
|
||||||
> queryExpr (CombineQueryExpr q1 ct q2) =
|
> queryExpr (CombineQueryExpr q1 ct d c q2) =
|
||||||
> sep [queryExpr q1
|
> sep [queryExpr q1
|
||||||
> ,text $ case ct of
|
> ,text (case ct of
|
||||||
> Union -> "union"
|
> Union -> "union"
|
||||||
> Intersect -> "intersect"
|
> Intersect -> "intersect"
|
||||||
> Except -> "except"
|
> Except -> "except")
|
||||||
|
> <+> case d of
|
||||||
|
> All -> empty
|
||||||
|
> Distinct -> text "distinct"
|
||||||
|
> <+> case c of
|
||||||
|
> Corresponding -> text "corresponding"
|
||||||
|
> Respectively -> empty
|
||||||
> ,queryExpr q2]
|
> ,queryExpr q2]
|
||||||
|
|
||||||
> selectList :: [(Maybe String, ScalarExpr)] -> Doc
|
> selectList :: [(Maybe String, ScalarExpr)] -> Doc
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
> ,Duplicates(..)
|
> ,Duplicates(..)
|
||||||
> ,Direction(..)
|
> ,Direction(..)
|
||||||
> ,CombineOp(..)
|
> ,CombineOp(..)
|
||||||
|
> ,Corresponding(..)
|
||||||
> ,TableRef(..)
|
> ,TableRef(..)
|
||||||
> ,JoinType(..)
|
> ,JoinType(..)
|
||||||
> ,JoinCondition(..)
|
> ,JoinCondition(..)
|
||||||
|
@ -69,6 +70,8 @@
|
||||||
> | CombineQueryExpr
|
> | CombineQueryExpr
|
||||||
> {qe1 :: QueryExpr
|
> {qe1 :: QueryExpr
|
||||||
> ,qeCombOp :: CombineOp
|
> ,qeCombOp :: CombineOp
|
||||||
|
> ,qeDuplicates :: Duplicates
|
||||||
|
> ,qeCorresponding :: Corresponding
|
||||||
> ,qe2 :: QueryExpr
|
> ,qe2 :: QueryExpr
|
||||||
> }
|
> }
|
||||||
> deriving (Eq,Show)
|
> deriving (Eq,Show)
|
||||||
|
@ -76,6 +79,7 @@
|
||||||
> data Duplicates = Distinct | All deriving (Eq,Show)
|
> data Duplicates = Distinct | All deriving (Eq,Show)
|
||||||
> data Direction = Asc | Desc deriving (Eq,Show)
|
> data Direction = Asc | Desc deriving (Eq,Show)
|
||||||
> data CombineOp = Union | Except | Intersect deriving (Eq,Show)
|
> data CombineOp = Union | Except | Intersect deriving (Eq,Show)
|
||||||
|
> data Corresponding = Corresponding | Respectively deriving (Eq,Show)
|
||||||
|
|
||||||
> makeSelect :: QueryExpr
|
> makeSelect :: QueryExpr
|
||||||
> makeSelect = Select {qeDuplicates = All
|
> makeSelect = Select {qeDuplicates = All
|
||||||
|
|
11
Tests.lhs
11
Tests.lhs
|
@ -365,11 +365,14 @@
|
||||||
> combos :: TestItem
|
> combos :: TestItem
|
||||||
> combos = Group "combos" $ map (uncurry TestQueryExpr)
|
> combos = Group "combos" $ map (uncurry TestQueryExpr)
|
||||||
> [("select a from t union select b from u"
|
> [("select a from t union select b from u"
|
||||||
> ,CombineQueryExpr ms1 Union ms2)
|
> ,CombineQueryExpr ms1 Union All Respectively ms2)
|
||||||
> ,("select a from t intersect select b from u"
|
> ,("select a from t intersect select b from u"
|
||||||
> ,CombineQueryExpr ms1 Intersect ms2)
|
> ,CombineQueryExpr ms1 Intersect All Respectively ms2)
|
||||||
> ,("select a from t except select b from u"
|
> ,("select a from t except all select b from u"
|
||||||
> ,CombineQueryExpr ms1 Except ms2)
|
> ,CombineQueryExpr ms1 Except All Respectively ms2)
|
||||||
|
> ,("select a from t union distinct corresponding \
|
||||||
|
> \select b from u"
|
||||||
|
> ,CombineQueryExpr ms1 Union Distinct Corresponding ms2)
|
||||||
> ]
|
> ]
|
||||||
> where
|
> where
|
||||||
> ms1 = makeSelect
|
> ms1 = makeSelect
|
||||||
|
|
Loading…
Reference in a new issue