added test: coalesceDefault with sub_select

The generated SQL code needs to wrap the sub-query in an extra pair of
parentheses.

I.e. the following is invalid SQL:

    COALESCE( SELECT ... , ... )

This is the correct syntax:

    COALESCE( (SELECT ...) , ... )
This commit is contained in:
Andreas Herrmann 2015-02-27 22:11:24 +01:00
parent f22a11d989
commit 0d76e0e090

View File

@ -592,6 +592,28 @@ main = do
, Value 5
]
it "works with sub-queries" $
run $ do
p1id <- insert p1
p2id <- insert p2
p3id <- insert p3
_ <- insert p4
_ <- insert p5
_ <- insert $ BlogPost "a" p1id
_ <- insert $ BlogPost "b" p2id
_ <- insert $ BlogPost "c" p3id
ret <- select $
from $ \b -> do
let sub =
from $ \p -> do
where_ (p ^. PersonId ==. b ^. BlogPostAuthorId)
return $ p ^. PersonAge
return $ coalesceDefault [sub_select sub] (val (42 :: Int))
liftIO $ ret `shouldBe` [ Value (36 :: Int)
, Value 42
, Value 17
]
#if defined(WITH_POSTGRESQL) || defined(WITH_MYSQL)
it "works on PostgreSQL and MySQL with <2 arguments" $
run $ do