improve do update set/excluded examples
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
508158112d
commit
3b72fefe23
2 changed files with 19 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
* 2.6.next in progress
|
* 2.6.next in progress
|
||||||
* Address [#527](https://github.com/seancorfield/honeysql/issues/527) by adding tests and more documentation for `:composite`.
|
* Address [#527](https://github.com/seancorfield/honeysql/issues/527) by adding tests and more documentation for `:composite`.
|
||||||
|
* Add example of mixed `DO UPDATE SET` with `EXCLUDED` and regular SQL expressions.
|
||||||
* Update Clojure versions (to 1.11.2 and 1.12.0-alpha9); update other dev/test dependencies.
|
* Update Clojure versions (to 1.11.2 and 1.12.0-alpha9); update other dev/test dependencies.
|
||||||
|
|
||||||
* 2.6.1126 -- 2024-03-04
|
* 2.6.1126 -- 2024-03-04
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,24 @@ DO UPDATE SET counter = table.counter + ?
|
||||||
" "id" 1 1]
|
" "id" 1 1]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can use `:EXCLUDED.column` in a hash map to produce the
|
||||||
|
same effect as `:column` in a vector:
|
||||||
|
|
||||||
|
```clojure
|
||||||
|
user=> (-> (insert-into :table)
|
||||||
|
(values [{:id "id" :counter 1}])
|
||||||
|
(on-conflict :id)
|
||||||
|
(do-update-set {:name :EXCLUDED.name
|
||||||
|
:counter [:+ :table.counter 1]})
|
||||||
|
(sql/format {:pretty true}))
|
||||||
|
["
|
||||||
|
INSERT INTO table (id, counter)
|
||||||
|
VALUES (?, ?)
|
||||||
|
ON CONFLICT (id)
|
||||||
|
DO UPDATE SET name = EXCLUDED.name, counter = table.counter + ?
|
||||||
|
" "id" 1 1]
|
||||||
|
```
|
||||||
|
|
||||||
If you need to combine a `DO UPDATE SET` hash map expression
|
If you need to combine a `DO UPDATE SET` hash map expression
|
||||||
with a `WHERE` clause, you need to explicitly use the `:fields` /
|
with a `WHERE` clause, you need to explicitly use the `:fields` /
|
||||||
`:where` format explained above. Here's how those two examples
|
`:where` format explained above. Here's how those two examples
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue