summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--src/clojure_sql/dsl.clj22
2 files changed, 15 insertions, 12 deletions
diff --git a/README.md b/README.md
index 8769248..1e2e638 100644
--- a/README.md
+++ b/README.md
@@ -214,8 +214,9 @@ be the return value of the associated query function call (`deref`,
* `sort` can now sort on expressions, not just table names
-* `union` and `intersection` queries will now have their `:fields` set
- correctly
+* `union` and `intersection` queries will now always introduce a
+ subquery, but they should now compose properly (previously they
+ would only join correctly)
* Provide `as-subobject` to help with renaming things with the dot
notation
diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj
index 015dfda..16bc2e5 100644
--- a/src/clojure_sql/dsl.clj
+++ b/src/clojure_sql/dsl.clj
@@ -370,19 +370,21 @@
(apply = (map (comp set keys :fields) queries))))
(defn union
- "Combine the results of two queries"
+ "Combine the results of two queries.
+
+ Will always introduce a subquery."
[& queries]
{:pre [(apply union-compatible? queries)]}
- (assoc (q/->Query)
- :set-operation :union
- :queries queries
- :fields (zipmap (keys (:fields (first queries))) (repeat nil))))
+ (convert-to-subquery (q/map->Query {:set-operation :union
+ :queries queries
+ :fields (zipmap (keys (:fields (first queries))) (repeat nil))})))
(defn intersection
- "Take the common rows in two queries"
+ "Take the common rows in two queries.
+
+ Will always introduce a subquery."
[& queries]
{:pre [(apply union-compatible? queries)]}
- (assoc (q/->Query)
- :set-operation :intersect
- :queries queries
- :fields (zipmap (keys (:fields (first queries))) (repeat nil))))
+ (convert-to-subquery (q/map->Query {:set-operation :intersect
+ :queries queries
+ :fields (zipmap (keys (:fields (first queries))) (repeat nil))})))