diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index f1175a3..ce112e4 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -507,7 +507,8 @@ attempt to fix the precedence and associativity. Doesn't work > ,return Nothing > ] > alias j = let a1 = optional (try (keyword_ "as")) *> identifierString -> in option j (JoinAlias j <$> try a1) +> a2 = optionMaybe (try $ parens (commaSep1 identifierString)) +> in option j (JoinAlias j <$> try a1 <*> try a2) > optionalScalarExpr :: String -> P (Maybe ScalarExpr) > optionalScalarExpr k = optionMaybe (try (keyword_ k) *> scalarExpr) diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 84ddc09..ccb4fc6 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -157,7 +157,9 @@ back into SQL source text. It attempts to format the output nicely. > ,nest 4 $ commaSep $ map tr ts] > where > tr (SimpleTableRef t) = text t -> tr (JoinAlias t a) = tr t <+> text "as" <+> text a +> tr (JoinAlias t a cs) = +> tr t <+> text "as" <+> text a +> <+> maybe empty (\cs' -> parens $ commaSep $ map text cs') cs > tr (JoinParens t) = parens $ tr t > tr (JoinQueryExpr q) = parens $ queryExpr q > tr (JoinTableRef jt t0 t1 jc) = diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index f7246a3..ab51c70 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -99,7 +99,7 @@ > data TableRef = SimpleTableRef String > | JoinTableRef JoinType TableRef TableRef (Maybe JoinCondition) > | JoinParens TableRef -> | JoinAlias TableRef String +> | JoinAlias TableRef String (Maybe [String]) > | JoinQueryExpr QueryExpr > deriving (Eq,Show) diff --git a/Tests.lhs b/Tests.lhs index 4059b0f..5cee6ad 100644 --- a/Tests.lhs +++ b/Tests.lhs @@ -289,12 +289,14 @@ > ,("select a from (select a from t)" > ,ms [JoinQueryExpr $ ms [SimpleTableRef "t"]]) > ,("select a from t as u" -> ,ms [JoinAlias (SimpleTableRef "t") "u"]) +> ,ms [JoinAlias (SimpleTableRef "t") "u" Nothing]) > ,("select a from t u" -> ,ms [JoinAlias (SimpleTableRef "t") "u"]) +> ,ms [JoinAlias (SimpleTableRef "t") "u" Nothing]) +> ,("select a from t u(b)" +> ,ms [JoinAlias (SimpleTableRef "t") "u" $ Just ["b"]]) > ,("select a from (t cross join u) as u" > ,ms [JoinAlias (JoinParens $ JoinTableRef Cross (SimpleTableRef "t") -> (SimpleTableRef "u") Nothing) "u"]) +> (SimpleTableRef "u") Nothing) "u" Nothing]) > ] > where > ms f = makeSelect {qeSelectList = [(Nothing,Iden "a")]