diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cec0ed..145fab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * 2.6.next in progress * 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. * 2.6.1126 -- 2024-03-04 diff --git a/doc/postgresql.md b/doc/postgresql.md index 1693b97..73b5e8d 100644 --- a/doc/postgresql.md +++ b/doc/postgresql.md @@ -293,6 +293,24 @@ DO UPDATE SET counter = table.counter + ? " "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 with a `WHERE` clause, you need to explicitly use the `:fields` / `:where` format explained above. Here's how those two examples