Skip to content

Commit 313ece1

Browse files
author
Anton Oellerer
authored
Update README.md
Add description for syntax when setting multiple [k, v] pairs on conflict
1 parent 153d775 commit 313ece1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ The query creation and usage is exactly the same as honeysql.
9292
sql/format)
9393
=> ["INSERT INTO distributors (did, dname) VALUES (23, ?) ON CONFLICT (did) DO UPDATE SET dname = ?" "Foo Distributors" "EXCLUDED.dname || ' (formerly ' || d.dname || ')'"]
9494
```
95+
To set multiple fields on conflict, add the `[k, v]` statements like this:
96+
```clj
97+
(-> (insert-into :distributors)
98+
(values [{:did 23 :dname "Foo Distributors"}])
99+
(psqlh/on-conflict :did)
100+
(psqlh/do-update-set! [:dname "EXCLUDED.dname || ' (formerly ' || distributors.dname || ')'"] [:downer "EXCLUDED.downer"])
101+
sql/format)
102+
=> ["INSERT INTO distributors (did, dname) VALUES (23, ?) ON CONFLICT (did) DO UPDATE SET dname = ?, downer = ?" "Foo Distributors" "EXCLUDED.dname || ' (formerly ' || d.dname || ')'" "EXCLUDED.downer"]
103+
```
95104

96105
### insert into with alias
97106
`insert-into-as` can be used to write insert statements with table name aliased.

0 commit comments

Comments
 (0)