diff --git a/src/honeysql/format.cljc b/src/honeysql/format.cljc index c0974b3..e7e323e 100644 --- a/src/honeysql/format.cljc +++ b/src/honeysql/format.cljc @@ -183,10 +183,10 @@ (def default-clause-priorities "Determines the order that clauses will be placed within generated SQL" - {:union 20 - :union-all 25 - :with 30 - :with-recursive 40 + {:with 20 + :with-recursive 30 + :union 40 + :union-all 45 :select 50 :insert-into 60 :update 70 diff --git a/test/honeysql/format_test.cljc b/test/honeysql/format_test.cljc index 3e6faf7..acc9cb3 100644 --- a/test/honeysql/format_test.cljc +++ b/test/honeysql/format_test.cljc @@ -121,3 +121,18 @@ (format {:select [:foo] :from [:bar] :where [:= [:mod :col1 4] [:+ :col2 4]]}))))) + +(deftest union-with-cte + (is (= (format {:union [{:select [:foo] :from [:bar1]} + {:select [:foo] :from [:bar2]}] + :with [[[:bar {:columns [:spam :eggs]}] + {:values [[1 2] [3 4] [5 6]]}]]}) + ["WITH bar (spam, eggs) AS (VALUES (?, ?), (?, ?), (?, ?)) SELECT foo FROM bar1 UNION SELECT foo FROM bar2" 1 2 3 4 5 6]))) + + +(deftest union-all-with-cte + (is (= (format {:union-all [{:select [:foo] :from [:bar1]} + {:select [:foo] :from [:bar2]}] + :with [[[:bar {:columns [:spam :eggs]}] + {:values [[1 2] [3 4] [5 6]]}]]}) + ["WITH bar (spam, eggs) AS (VALUES (?, ?), (?, ?), (?, ?)) SELECT foo FROM bar1 UNION ALL SELECT foo FROM bar2" 1 2 3 4 5 6])))