1
Fork 0

get group by variations working

This commit is contained in:
Jake Wheat 2013-12-17 19:27:09 +02:00
parent b703e04af3
commit 74c6d39b23
2 changed files with 25 additions and 4 deletions

View file

@ -601,7 +601,19 @@ where, having, limit, offset).
> sgroupBy :: P [GroupingExpr] > sgroupBy :: P [GroupingExpr]
> sgroupBy = try (keyword_ "group") > sgroupBy = try (keyword_ "group")
> *> keyword_ "by" > *> keyword_ "by"
> *> commaSep1 (SimpleGroup <$> scalarExpr) > *> commaSep1 groupingExpression
> where
> groupingExpression =
> choice
> [try (keyword_ "cube") >>
> Cube <$> parens (commaSep groupingExpression)
> ,try (keyword_ "rollup") >>
> Rollup <$> parens (commaSep groupingExpression)
> ,GroupingParens <$> parens (commaSep groupingExpression)
> ,try (keyword_ "grouping") >> keyword_ "sets" >>
> GroupingSets <$> parens (commaSep groupingExpression)
> ,SimpleGroup <$> scalarExpr
> ]
> having :: P ScalarExpr > having :: P ScalarExpr
> having = keywordScalarExpr "having" > having = keywordScalarExpr "having"

View file

@ -38,9 +38,14 @@ sure which sql version they were introduced, 1999 or 2003 I think).
> newGroupBy :: TestItem > newGroupBy :: TestItem
> newGroupBy = Group "newGroupBy" $ map (uncurry TestQueryExpr) > newGroupBy = Group "newGroupBy" $ map (uncurry TestQueryExpr)
> [ > [("select * from t group by ()", ms [GroupingParens []])
> ,("select * from t group by grouping sets ((), (a))"
group by () > ,ms [GroupingSets [GroupingParens []
> ,GroupingParens [SimpleGroup $ Iden "a"]]])
> ,("select * from t group by cube(a,b)"
> ,ms [Cube [SimpleGroup $ Iden "a", SimpleGroup $ Iden "b"]])
> ,("select * from t group by rollup(a,b)"
> ,ms [Rollup [SimpleGroup $ Iden "a", SimpleGroup $ Iden "b"]])
GROUP BY a GROUP BY a
@ -224,3 +229,7 @@ GROUP BY CUBE(MONTH(SALES_DATE),REGION)
ORDER BY MONTH, REGION ORDER BY MONTH, REGION
> ] > ]
> where
> ms g = makeSelect {qeSelectList = [(Nothing,Star)]
> ,qeFrom = [TRSimple "t"]
> ,qeGroupBy = g}