diff --git a/CHANGELOG.md b/CHANGELOG.md index a8617c9..35b0fbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changes * 2.1.next in progress - * Fix #371 by always parenthesizing the operand of `NOT`. + * 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`. * 2.1.818 -- 2021-10-04 * Fix #367 by supporting parameters in subexpressions around `IS NULL` / `IS NOT NULL` tests. diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 34c9d24..b97a295 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -868,7 +868,9 @@ :drop-materialized-view #'format-drop-items :refresh-materialized-view (fn [_ x] (format-create :refresh :materialized-view x nil)) :raw (fn [_ x] (raw-render x)) - :nest (fn [_ x] (format-expr x {:nested true})) + :nest (fn [_ x] + (let [[sql & params] (format-expr x)] + (into [(str "(" sql ")")] params))) :with #'format-with :with-recursive #'format-with :intersect #'format-on-set-op @@ -1180,7 +1182,8 @@ {::wrapper (fn [fx _] (fx))})])) :nest (fn [_ [x]] - (format-expr x {:nested true})) + (let [[sql & params] (format-expr x)] + (into [(str "(" sql ")")] params))) :not (fn [_ [x]] (let [[sql & params] (format-expr x {:nested true})]