implement extract
This commit is contained in:
parent
a001d120c1
commit
5e56a4b560
|
@ -172,6 +172,13 @@ to be.
|
||||||
> prefixCast = try (CastOp <$> typeName
|
> prefixCast = try (CastOp <$> typeName
|
||||||
> <*> stringLiteral)
|
> <*> stringLiteral)
|
||||||
|
|
||||||
|
> extract :: P ScalarExpr
|
||||||
|
> extract = try (keyword_ "extract") >>
|
||||||
|
> parens (makeOp <$> identifierString
|
||||||
|
> <*> (keyword_ "from"
|
||||||
|
> *> scalarExpr'))
|
||||||
|
> where makeOp n e = SpecialOp "extract" [Iden n, e]
|
||||||
|
|
||||||
> inSuffix :: ScalarExpr -> P ScalarExpr
|
> inSuffix :: ScalarExpr -> P ScalarExpr
|
||||||
> inSuffix e =
|
> inSuffix e =
|
||||||
> In
|
> In
|
||||||
|
@ -289,7 +296,7 @@ postgresql handles this
|
||||||
> factor = choice [literal
|
> factor = choice [literal
|
||||||
> ,scase
|
> ,scase
|
||||||
> ,cast
|
> ,cast
|
||||||
> --,extract
|
> ,extract
|
||||||
> ,subquery
|
> ,subquery
|
||||||
> ,prefixUnaryOp
|
> ,prefixUnaryOp
|
||||||
> ,try app
|
> ,try app
|
||||||
|
|
|
@ -35,6 +35,11 @@ back into SQL source text. It attempts to format the output nicely.
|
||||||
> ,text nm <+> scalarExpr b
|
> ,text nm <+> scalarExpr b
|
||||||
> ,text "and" <+> scalarExpr c]
|
> ,text "and" <+> scalarExpr c]
|
||||||
|
|
||||||
|
> scalarExpr (SpecialOp "extract" [a,n]) =
|
||||||
|
> text "extract" <> parens (scalarExpr a
|
||||||
|
> <+> text "from"
|
||||||
|
> <+> scalarExpr n)
|
||||||
|
|
||||||
> scalarExpr (SpecialOp nm es) =
|
> scalarExpr (SpecialOp nm es) =
|
||||||
> text nm <+> parens (commaSep $ map scalarExpr es)
|
> text nm <+> parens (commaSep $ map scalarExpr es)
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@
|
||||||
> ,("a is similar to b", BinOp "is similar to" (Iden "a") (Iden "b"))
|
> ,("a is similar to b", BinOp "is similar to" (Iden "a") (Iden "b"))
|
||||||
> ,("a is not similar to b", BinOp "is not similar to" (Iden "a") (Iden "b"))
|
> ,("a is not similar to b", BinOp "is not similar to" (Iden "a") (Iden "b"))
|
||||||
> ,("a overlaps b", BinOp "overlaps" (Iden "a") (Iden "b"))
|
> ,("a overlaps b", BinOp "overlaps" (Iden "a") (Iden "b"))
|
||||||
> --,("extract(day from t)", SpecialOp "extract" [Iden "day", Iden "t"])
|
> ,("extract(day from t)", SpecialOp "extract" [Iden "day", Iden "t"])
|
||||||
> ]
|
> ]
|
||||||
|
|
||||||
> aggregates :: TestItem
|
> aggregates :: TestItem
|
||||||
|
|
Loading…
Reference in a new issue