From a0d0880ac637a7005ca41704a20fc74d57ee36a4 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 12 Oct 2016 09:26:51 -0700 Subject: [PATCH] Add an additional test for phrasing complex UNION queries. --- test/honeysql/format_test.cljc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/honeysql/format_test.cljc b/test/honeysql/format_test.cljc index e1083bc..5e140dc 100644 --- a/test/honeysql/format_test.cljc +++ b/test/honeysql/format_test.cljc @@ -96,3 +96,17 @@ (is (= (format {:intersect [{:select [:foo] :from [:bar1]} {:select [:foo] :from [:bar2]}]}) ["SELECT foo FROM bar1 INTERSECT SELECT foo FROM bar2"]))) + +(deftest inner-parts-test + (testing "The correct way to apply ORDER BY to various parts of a UNION" + (is (= (format + {:union + [{:select [:amount :id :created_on] + :from [:transactions]} + {:select [:amount :id :created_on] + :from [{:select [:amount :id :created_on] + :from [:other_transactions] + :order-by [[:amount :desc]] + :limit 5}]}] + :order-by [[:amount :asc]]}) + ["SELECT amount, id, created_on FROM transactions UNION SELECT amount, id, created_on FROM (SELECT amount, id, created_on FROM other_transactions ORDER BY amount DESC LIMIT ?) ORDER BY amount ASC" 5]))))