summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-07-03 18:32:58 +1000
committerCarlo Zancanaro <carlo@clearboxsystems.com.au>2013-07-03 18:32:58 +1000
commit9a60253ba229769299720ef320ea465e33fa4c92 (patch)
tree59a968e68780ffc286ab8cd5346ab1988042bccb /src
parent7ca4f6e7876e8fd577b74998975dadd44e06e8a1 (diff)
Add fields to union/intersection result queries
Diffstat (limited to 'src')
-rw-r--r--src/clojure_sql/dsl.clj11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj
index 5eae2d7..c94f678 100644
--- a/src/clojure_sql/dsl.clj
+++ b/src/clojure_sql/dsl.clj
@@ -221,7 +221,6 @@
right (reduce (fn [query [alias table]]
(rename-table query alias (keyword (gensym (name table)))))
right (:tables right))
- ;;_ (assert (empty? common-tables) "Cannot join two tables with the same name")
merged-tables (merge (:tables left) (:tables right))
common-fields (set/intersection (set (keys (:fields left)))
(set (keys (:fields right))))
@@ -385,15 +384,17 @@
(defn union
"Combine the results of two queries"
[& queries]
- (assert (apply union-compatible? queries) "Unioned queries must expose the same fields.")
+ {:pre [(apply union-compatible? queries)]}
(assoc (q/->Query)
:set-operation :union
- :queries queries))
+ :queries queries
+ :fields (zipmap (keys (:fields (first queries))) (repeat nil))))
(defn intersection
"Take the common rows in two queries"
[& queries]
- (assert (apply union-compatible? queries) "Unioned queries must expose the same fields.")
+ {:pre [(apply union-compatible? queries)]}
(assoc (q/->Query)
:set-operation :intersect
- :queries queries))
+ :queries queries
+ :fields (zipmap (keys (:fields (first queries))) (repeat nil))))