diff --git a/CHANGELOG.md b/CHANGELOG.md index 5445fc8..ab02980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes +* 2.1.next in progress + * Fix #372 by merging `:select-distinct-on` differently. + * Update `build-clj` to v0.6.0. + * 2.1.829 -- 2021-11-27 * Fix #371 by treating the operand of `NOT` as a nested expression (so it is parenthesized unless it is a simple value). * Fix #370 by **always** parenthesizing the operand of `:nest`. diff --git a/deps.edn b/deps.edn index f197156..d508fc1 100644 --- a/deps.edn +++ b/deps.edn @@ -4,7 +4,7 @@ :aliases {;; for help: clojure -A:deps -T:build help/doc :build {:deps {io.github.seancorfield/build-clj - {:git/tag "v0.5.5" :git/sha "0527130"}} + {:git/tag "v0.6.0" :git/sha "2451bea"}} :ns-default build} ;; versions to test against: diff --git a/src/honey/sql/helpers.cljc b/src/honey/sql/helpers.cljc index 1f5c401..6fa3f6d 100644 --- a/src/honey/sql/helpers.cljc +++ b/src/honey/sql/helpers.cljc @@ -110,10 +110,20 @@ (simplify-logic)) current))) +(defn- select-distinct-on-merge + "Since the first argument in a group is special, we + need to merge that, and then merge the other args." + [[c-on & current] [a-on & args]] + (-> (c/into (vec c-on) a-on) + (vector) + (c/into current) + (c/into args))) + (def ^:private special-merges "Identify the conjunction merge clauses." - {:where #'conjunction-merge - :having #'conjunction-merge}) + {:select-distinct-on #'select-distinct-on-merge + :where #'conjunction-merge + :having #'conjunction-merge}) (defn- helper-merge [data k args] (if-let [merge-fn (special-merges k)] @@ -400,6 +410,12 @@ [& args] (generic :select-distinct-on args)) +(comment + (= (select-distinct-on [:a :b] :c [:d :dd]) + (-> (select-distinct-on [:a] :c) + (select-distinct-on [:b] [:d :dd]))) + ) + (defn select-top "Accepts a TOP expression, followed by any number of column names, or column/alias pairs, or SQL expressions