From 0d76e0e09032745088d3fcc56861820e936be244 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Fri, 27 Feb 2015 22:11:24 +0100 Subject: [PATCH] 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 ...) , ... ) --- test/Test.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/Test.hs b/test/Test.hs index ce9cecf..2a4d6af 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -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