Skip to content

Commit 293165f

Browse files
committed
Fix query-values priority
When used with an upsert clause, query-values was not being rendered with the correct priority. The provided test fails on master and passes on this branch. It was previously rendering the SQL as: ``` INSERT INTO distributors (did, dname) ON CONFLICT ON CONSTRAINT distributors_pkey DO NOTHING (SELECT ?, ?) ``` which is not valid SQL. The below snippet from psql demonstrates this not working: ``` muncher=# insert into foo (id) select 1 on conflict do nothing; INSERT 0 1 muncher=# insert into foo (id) on conflict do nothing (select 1); ERROR: syntax error at or near "on" LINE 1: insert into foo (id) on conflict do nothing (select 1); ```
1 parent d45d510 commit 293165f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/honeysql_postgres/format.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
:offset 210
4646
:lock 215
4747
:values 220
48-
:query-values 250}
48+
:query-values 221}
4949
custom-additions))
5050

5151
(defn override-default-clause-priority

test/honeysql_postgres/postgres_test.cljc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
add-column partition-by insert-into-as
88
create-table rename-table drop-table
99
window create-view over with-columns]]
10-
[honeysql.helpers :as sqlh :refer [insert-into values where select
11-
from order-by update sset]]
10+
[honeysql.helpers :as sqlh :refer [insert-into values where select columns
11+
from order-by update sset query-values]]
1212
[honeysql.core :as sql]
1313
[clojure.test :as test :refer [deftest is testing]]))
1414

@@ -45,6 +45,13 @@
4545
(values [{:did 23 :dname "Foo Distributors"}])
4646
(on-conflict :did)
4747
(do-update-set! [:dname "EXCLUDED.dname || ' (formerly ' || d.dname || ')'"])
48+
sql/format)))
49+
(is (= ["INSERT INTO distributors (did, dname) (SELECT ?, ?) ON CONFLICT ON CONSTRAINT distributors_pkey DO NOTHING" 1 "whatever"]
50+
(-> (insert-into :distributors)
51+
(columns :did :dname)
52+
(query-values (select 1 "whatever"))
53+
(upsert (-> (on-conflict-constraint :distributors_pkey)
54+
do-nothing))
4855
sql/format)))))
4956

5057

0 commit comments

Comments
 (0)