diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 02e1989..1987759 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -902,15 +902,15 @@ [sets & set-params] (if (map? fields) (format-set-exprs k fields) - [(str/join ", " - (map (fn [e] - (let [e (format-entity e {:drop-ns true})] - (str e " = EXCLUDED." e))) - fields))]) + [(str (sql-kw k) " " + (str/join ", " + (map (fn [e] + (let [e (format-entity e {:drop-ns true})] + (str e " = EXCLUDED." e))) + fields)))]) where (or (:where x) ('where x)) [sql & params] (when where (format-dsl {:where where}))] - (-> [(str (sql-kw k) " " sets - (when sql (str " " sql)))] + (-> [(str sets (when sql (str " " sql)))] (into set-params) (into params))) (format-set-exprs k x)) diff --git a/test/honey/sql/postgres_test.cljc b/test/honey/sql/postgres_test.cljc index c6ff2b8..56fc1a5 100644 --- a/test/honey/sql/postgres_test.cljc +++ b/test/honey/sql/postgres_test.cljc @@ -93,14 +93,14 @@ (upsert (-> (on-conflict (on-constraint :distributors_pkey)) do-nothing)) sql/format))) - (is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET DO UPDATE SET into = ((STATE(?), MODIFIED(NOW()))) WHERE state = ?" 1 42 "enabled" "disabled"] + (is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET into = ((STATE(?), MODIFIED(NOW()))) WHERE state = ?" 1 42 "enabled" "disabled"] (sql/format (-> (insert-into :foo) (values [{:id 1 :data 42}]) (upsert (-> (on-conflict :id) (do-update-set [:state "enabled"] [:modified [:now]]) (where [:= :state "disabled"]))))))) - (is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET DO UPDATE SET state = ?, modified = NOW() WHERE state = ?" 1 42 "enabled" "disabled"] + (is (= ["INSERT INTO foo (id, data) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET state = ?, modified = NOW() WHERE state = ?" 1 42 "enabled" "disabled"] (sql/format (-> (insert-into :foo) (values [{:id 1 :data 42}]) (upsert (-> (on-conflict :id)