add support for full table aliases
This commit is contained in:
parent
d005dc1706
commit
15c83555ff
|
@ -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)
|
||||
|
|
|
@ -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) =
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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")]
|
||||
|
|
Loading…
Reference in a new issue