add support for values
This commit is contained in:
parent
4330b3d7e0
commit
c52334943f
|
@ -599,7 +599,7 @@ and union, etc..
|
|||
> queryExpr :: P QueryExpr
|
||||
> queryExpr =
|
||||
> choice [with
|
||||
> ,select >>= optionSuffix queryExprSuffix]
|
||||
> ,choice [values,select] >>= optionSuffix queryExprSuffix]
|
||||
> where
|
||||
> select = try (keyword_ "select") >>
|
||||
> Select
|
||||
|
@ -612,6 +612,8 @@ and union, etc..
|
|||
> <*> option [] orderBy
|
||||
> <*> optionMaybe limit
|
||||
> <*> optionMaybe offset
|
||||
> values = try (keyword_ "values")
|
||||
> >> Values <$> commaSep (parens (commaSep scalarExpr))
|
||||
|
||||
> queryExprSuffix :: QueryExpr -> P QueryExpr
|
||||
> queryExprSuffix qe =
|
||||
|
|
|
@ -177,6 +177,9 @@
|
|||
> (vcat $ punctuate comma $ flip map withs $ \(n,q) ->
|
||||
> name n <+> text "as" <+> parens (queryExpr q))
|
||||
> ,queryExpr qe]
|
||||
> queryExpr (Values vs) =
|
||||
> text "values"
|
||||
> <+> nest 7 (commaSep (map (parens . commaSep . map scalarExpr) vs))
|
||||
|
||||
> selectList :: [(Maybe Name, ScalarExpr)] -> Doc
|
||||
> selectList is = commaSep $ map si is
|
||||
|
|
|
@ -159,6 +159,8 @@
|
|||
> ,qe2 :: QueryExpr
|
||||
> }
|
||||
> | With [(Name,QueryExpr)] QueryExpr
|
||||
> | Values [[ScalarExpr]]
|
||||
|
||||
> deriving (Eq,Show,Read)
|
||||
|
||||
TODO: add queryexpr parens to deal with e.g.
|
||||
|
|
|
@ -122,7 +122,7 @@ queries section
|
|||
|
||||
> ,"SELECT DISTINCT select_list t"
|
||||
|
||||
> --,"VALUES (1, 'one'), (2, 'two'), (3, 'three');" -- values list
|
||||
> ,"VALUES (1, 'one'), (2, 'two'), (3, 'three');"
|
||||
|
||||
> ,"SELECT 1 AS column1, 'one' AS column2\n\
|
||||
> \UNION ALL\n\
|
||||
|
@ -130,8 +130,7 @@ queries section
|
|||
> \UNION ALL\n\
|
||||
> \SELECT 3, 'three';"
|
||||
|
||||
> --,"SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter);"
|
||||
> -- values list
|
||||
> ,"SELECT * FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter);"
|
||||
|
||||
> ,"WITH regional_sales AS (\n\
|
||||
> \ SELECT region, SUM(amount) AS total_sales\n\
|
||||
|
|
|
@ -23,6 +23,7 @@ These are a few misc tests which don't fit anywhere else.
|
|||
> ,limit
|
||||
> ,combos
|
||||
> ,withQueries
|
||||
> ,values
|
||||
> ]
|
||||
|
||||
|
||||
|
@ -185,3 +186,10 @@ These are a few misc tests which don't fit anywhere else.
|
|||
> ms1 = ms "a" "t"
|
||||
> ms2 = ms "a" "u"
|
||||
> ms3 = ms "a" "x"
|
||||
|
||||
> values :: TestItem
|
||||
> values = Group "values" $ map (uncurry TestQueryExpr)
|
||||
> [("values (1,2),(3,4)"
|
||||
> ,Values [[NumLit "1", NumLit "2"]
|
||||
> ,[NumLit "3", NumLit "4"]])
|
||||
> ]
|
||||
|
|
Loading…
Reference in a new issue