Avoid wrapping QUERY with parens while formatting INSERT INTO ... QUERY

This also adds a test using honeysql.format/format for an existing
format-clause test case for :insert-into which encodes the previously
failing behavior.
This commit is contained in:
Brandon Adams 2017-12-12 16:09:31 -06:00
parent faba02f2b4
commit c7df208e3e
2 changed files with 5 additions and 2 deletions

View file

@ -540,7 +540,8 @@
(str "INSERT INTO "
(to-sql (ffirst table))
" (" (comma-join (map to-sql (second (first table)))) ") "
(to-sql (second table)))
(binding [*subquery?* false]
(to-sql (second table))))
(str "INSERT INTO " (to-sql table))))
(defmethod format-clause :columns [[_ fields] _]

View file

@ -58,7 +58,9 @@
(is (= (format-clause (first {:insert-into [:foo {:select [:bar] :from [:baz]}]}) nil)
"INSERT INTO foo SELECT bar FROM baz"))
(is (= (format-clause (first {:insert-into [[:foo [:a :b :c]] {:select [:d :e :f] :from [:baz]}]}) nil)
"INSERT INTO foo (a, b, c) SELECT d, e, f FROM baz")))
"INSERT INTO foo (a, b, c) SELECT d, e, f FROM baz"))
(is (= (format {:insert-into [[:foo [:a :b :c]] {:select [:d :e :f] :from [:baz]}]})
["INSERT INTO foo (a, b, c) SELECT d, e, f FROM baz"])))
(deftest exists-test
(is (= (format {:exists {:select [:a] :from [:foo]}})