1
Fork 0

add names/docs to some of the scalar expr constuctor fields, add partial support for explicit window frames

This commit is contained in:
Jake Wheat 2013-12-17 17:29:49 +02:00
parent bfe07dce53
commit e85ab8b831
5 changed files with 131 additions and 25 deletions
Language/SQL/SimpleSQL

View file

@ -52,21 +52,34 @@
> <+> commaSep (map scalarExpr es)
> <+> orderBy od)
> scalarExpr (WindowApp f es pb od) =
> scalarExpr (WindowApp f es pb od fr) =
> name f <> parens (commaSep $ map scalarExpr es)
> <+> text "over"
> <+> parens ((case pb of
> [] -> empty
> _ -> text "partition by"
> <+> nest 13 (commaSep $ map scalarExpr pb))
> <+> orderBy od)
> <+> orderBy od
> <+> maybe empty frd fr)
> where
> frd (FrameFrom rs fp) = rsd rs <+> fpd fp
> frd (FrameBetween rs fps fpe) =
> rsd rs <+> text "between" <+> fpd fps
> <+> text "and" <+> fpd fpe
> rsd rs = case rs of
> FrameRows -> text "rows"
> FrameRange -> text "range"
> fpd UnboundedPreceding = text "unbounded preceding"
> fpd UnboundedFollowing = text "unbounded following"
> fpd Current = text "current row"
> fpd (Preceding e) = scalarExpr e <+> text "preceding"
> fpd (Following e) = scalarExpr e <+> text "following"
> scalarExpr (SpecialOp nm [a,b,c]) | nm `elem` [Name "between"
> ,Name "not between"] =
> sep [scalarExpr a
> ,name nm <+> scalarExpr b
> ,nest (length (unname nm) + 1)
> $ text "and" <+> scalarExpr c]
> ,nest (length (unname nm) + 1) $ text "and" <+> scalarExpr c]
> scalarExpr (SpecialOp (Name "extract") [a,n]) =
> text "extract" <> parens (scalarExpr a