diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index 8853d4a..0ef328a 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -1482,8 +1482,11 @@ allows offset and fetch in either order > With <$> option False (True <$ keyword_ "recursive") > <*> commaSep1 withQuery <*> queryExpr > where -> withQuery = (,) <$> (fromAlias <* keyword_ "as") +> withQuery = (,) <$> (withAlias <* keyword_ "as") > <*> parens queryExpr +> withAlias = Alias <$> name <*> columnAliases +> columnAliases = optionMaybe $ parens $ commaSep1 name + == query expression diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 52aaa15..1273ef5 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -360,8 +360,13 @@ which have been changed to try to improve the layout of the output. > text "with" <+> (if rc then text "recursive" else empty) > <+> vcat [nest 5 > (vcat $ punctuate comma $ flip map withs $ \(n,q) -> -> alias n <+> text "as" <+> parens (queryExpr d q)) +> withAlias n <+> text "as" <+> parens (queryExpr d q)) > ,queryExpr d qe] +> where +> withAlias (Alias nm cols) = name nm +> <+> me (parens . commaSep . map name) cols + + > queryExpr d (Values vs) = > text "values" > <+> nest 7 (commaSep (map (parens . commaSep . map (scalarExpr d)) vs))