2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
These are the tests for parsing focusing on the from part of query
|
|
|
|
expression
|
|
|
|
|
|
|
|
> module Language.SQL.SimpleSQL.TableRefs (tableRefTests) where
|
|
|
|
|
|
|
|
> import Language.SQL.SimpleSQL.TestTypes
|
|
|
|
> import Language.SQL.SimpleSQL.Syntax
|
|
|
|
|
|
|
|
|
|
|
|
> tableRefTests :: TestItem
|
2016-02-12 11:51:06 +01:00
|
|
|
> tableRefTests = Group "tableRefTests" $ map (uncurry (TestQueryExpr ansi2011))
|
2013-12-17 10:40:31 +01:00
|
|
|
> [("select a from t"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRSimple [Name Nothing "t"]])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
2013-12-17 11:33:33 +01:00
|
|
|
> ,("select a from f(a)"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRFunction [Name Nothing "f"] [Iden [Name Nothing "a"]]])
|
2013-12-17 11:33:33 +01:00
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> ,("select a from t,u"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRSimple [Name Nothing "t"], TRSimple [Name Nothing "u"]])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
2014-01-22 08:54:14 +01:00
|
|
|
> ,("select a from s.t"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRSimple [Name Nothing "s", Name Nothing "t"]])
|
2014-01-22 08:54:14 +01:00
|
|
|
|
2013-12-17 11:45:32 +01:00
|
|
|
these lateral queries make no sense but the syntax is valid
|
|
|
|
|
|
|
|
> ,("select a from lateral a"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRLateral $ TRSimple [Name Nothing "a"]])
|
2013-12-17 11:45:32 +01:00
|
|
|
|
|
|
|
> ,("select a from lateral a,b"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRLateral $ TRSimple [Name Nothing "a"], TRSimple [Name Nothing "b"]])
|
2013-12-17 11:45:32 +01:00
|
|
|
|
2013-12-17 15:33:56 +01:00
|
|
|
> ,("select a from a, lateral b"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRSimple [Name Nothing "a"], TRLateral $ TRSimple [Name Nothing "b"]])
|
2013-12-17 11:45:32 +01:00
|
|
|
|
|
|
|
> ,("select a from a natural join lateral b"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "a"]) True JInner
|
|
|
|
> (TRLateral $ TRSimple [Name Nothing "b"])
|
2014-04-19 10:18:29 +02:00
|
|
|
> Nothing])
|
2013-12-17 11:45:32 +01:00
|
|
|
|
2013-12-17 15:33:56 +01:00
|
|
|
> ,("select a from lateral a natural join lateral b"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRLateral $ TRSimple [Name Nothing "a"]) True JInner
|
|
|
|
> (TRLateral $ TRSimple [Name Nothing "b"])
|
2014-04-19 10:18:29 +02:00
|
|
|
> Nothing])
|
2013-12-17 11:45:32 +01:00
|
|
|
|
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> ,("select a from t inner join u on expr"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False JInner (TRSimple [Name Nothing "u"])
|
|
|
|
> (Just $ JoinOn $ Iden [Name Nothing "expr"])])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
2013-12-17 11:27:00 +01:00
|
|
|
> ,("select a from t join u on expr"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False JInner (TRSimple [Name Nothing "u"])
|
|
|
|
> (Just $ JoinOn $ Iden [Name Nothing "expr"])])
|
2013-12-17 11:27:00 +01:00
|
|
|
|
2013-12-17 10:40:31 +01:00
|
|
|
> ,("select a from t left join u on expr"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False JLeft (TRSimple [Name Nothing "u"])
|
|
|
|
> (Just $ JoinOn $ Iden [Name Nothing "expr"])])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t right join u on expr"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False JRight (TRSimple [Name Nothing "u"])
|
|
|
|
> (Just $ JoinOn $ Iden [Name Nothing "expr"])])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t full join u on expr"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False JFull (TRSimple [Name Nothing "u"])
|
|
|
|
> (Just $ JoinOn $ Iden [Name Nothing "expr"])])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t cross join u"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False
|
|
|
|
> JCross (TRSimple [Name Nothing "u"]) Nothing])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t natural inner join u"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) True JInner (TRSimple [Name Nothing "u"])
|
2014-04-19 10:18:29 +02:00
|
|
|
> Nothing])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t inner join u using(a,b)"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRJoin (TRSimple [Name Nothing "t"]) False JInner (TRSimple [Name Nothing "u"])
|
|
|
|
> (Just $ JoinUsing [Name Nothing "a", Name Nothing "b"])])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from (select a from t)"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRQueryExpr $ ms [TRSimple [Name Nothing "t"]]])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t as u"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRAlias (TRSimple [Name Nothing "t"]) (Alias (Name Nothing "u") Nothing)])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t u"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRAlias (TRSimple [Name Nothing "t"]) (Alias (Name Nothing "u") Nothing)])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from t u(b)"
|
2016-02-12 13:13:47 +01:00
|
|
|
> ,ms [TRAlias (TRSimple [Name Nothing "t"]) (Alias (Name Nothing "u") $ Just [Name Nothing "b"])])
|
2013-12-17 10:40:31 +01:00
|
|
|
|
|
|
|
> ,("select a from (t cross join u) as u"
|
|
|
|
> ,ms [TRAlias (TRParens $
|
2016-02-12 13:13:47 +01:00
|
|
|
> TRJoin (TRSimple [Name Nothing "t"]) False JCross (TRSimple [Name Nothing "u"]) Nothing)
|
|
|
|
> (Alias (Name Nothing "u") Nothing)])
|
2013-12-17 10:40:31 +01:00
|
|
|
> -- todo: not sure if the associativity is correct
|
|
|
|
|
|
|
|
> ,("select a from t cross join u cross join v",
|
|
|
|
> ms [TRJoin
|
2016-02-12 13:13:47 +01:00
|
|
|
> (TRJoin (TRSimple [Name Nothing "t"]) False
|
|
|
|
> JCross (TRSimple [Name Nothing "u"]) Nothing)
|
|
|
|
> False JCross (TRSimple [Name Nothing "v"]) Nothing])
|
2013-12-17 10:40:31 +01:00
|
|
|
> ]
|
|
|
|
> where
|
2016-02-12 13:13:47 +01:00
|
|
|
> ms f = makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing)]
|
2013-12-17 10:40:31 +01:00
|
|
|
> ,qeFrom = f}
|