diff --git a/CHANGES.md b/CHANGES.md index 3a769b5..f64cbb4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,7 @@ ## 0.6.3 In development +* Add support for :intersect clause (@jakemcc) + ## 0.6.2 Support column names in :with clauses (@emidln) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index 73234f0..3635e6a 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -531,6 +531,9 @@ (defmethod format-clause :union-all [[_ maps] _] (string/join " UNION ALL " (map to-sql maps))) +(defmethod format-clause :intersect [[_ maps] _] + (string/join " INTERSECT " (map to-sql maps))) + (defmethod fn-handler "case" [_ & clauses] (str "CASE " (space-join diff --git a/src/honeysql/helpers.clj b/src/honeysql/helpers.clj index a9825b3..2548b82 100644 --- a/src/honeysql/helpers.clj +++ b/src/honeysql/helpers.clj @@ -236,3 +236,6 @@ (defmethod build-clause :union-all [_ m maps] (assoc m :union-all maps)) + +(defmethod build-clause :intersect [_ m maps] + (assoc m :intersect maps)) diff --git a/test/honeysql/format_test.clj b/test/honeysql/format_test.clj index 5568311..6ccbe52 100644 --- a/test/honeysql/format_test.clj +++ b/test/honeysql/format_test.clj @@ -79,3 +79,8 @@ (is (= (format {:union-all [{:select [:foo] :from [:bar1]} {:select [:foo] :from [:bar2]}]}) ["(SELECT foo FROM bar1) UNION ALL (SELECT foo FROM bar2)"]))) + +(deftest intersect-test + (is (= (format {:intersect [{:select [:foo] :from [:bar1]} + {:select [:foo] :from [:bar2]}]}) + ["(SELECT foo FROM bar1) INTERSECT (SELECT foo FROM bar2)"])))