diff --git a/CHANGELOG.md b/CHANGELOG.md index ea01e95..a8617c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes +* 2.1.next in progress + * Fix #371 by always parenthesizing the operand of `NOT`. + * 2.1.818 -- 2021-10-04 * Fix #367 by supporting parameters in subexpressions around `IS NULL` / `IS NOT NULL` tests. * Address #366 by introducing `:values-default-columns` option to control whether missing columns are treated as `NULL` or `DEFAULT` in `:values` clauses with sequences of hash maps. diff --git a/doc/special-syntax.md b/doc/special-syntax.md index 0bf4d4a..231690e 100644 --- a/doc/special-syntax.md +++ b/doc/special-syntax.md @@ -210,7 +210,7 @@ in front of it: (sql/format-expr [:not nil]) ;;=> ["NOT NULL"] (sql/format-expr [:not [:= :x 42]]) -;;=> ["NOT x = ?" 42] +;;=> ["NOT (x = ?)" 42] ``` ## order-by diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index f5b23eb..34c9d24 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -868,7 +868,7 @@ :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)) + :nest (fn [_ x] (format-expr x {:nested true})) :with #'format-with :with-recursive #'format-with :intersect #'format-on-set-op @@ -1183,7 +1183,7 @@ (format-expr x {:nested true})) :not (fn [_ [x]] - (let [[sql & params] (format-expr x)] + (let [[sql & params] (format-expr x {:nested true})] (into [(str "NOT " sql)] params))) :order-by (fn [k [e q]]