From 313ece12336b7581e12c0916a93ee3cf33bcd0cc Mon Sep 17 00:00:00 2001 From: Anton Oellerer Date: Mon, 12 Aug 2019 12:08:47 +0200 Subject: [PATCH 1/2] Update README.md Add description for syntax when setting multiple [k, v] pairs on conflict --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 085077a..3ddff47 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,15 @@ The query creation and usage is exactly the same as honeysql. sql/format) => ["INSERT INTO distributors (did, dname) VALUES (23, ?) ON CONFLICT (did) DO UPDATE SET dname = ?" "Foo Distributors" "EXCLUDED.dname || ' (formerly ' || d.dname || ')'"] ``` +To set multiple fields on conflict, add the `[k, v]` statements like this: +```clj +(-> (insert-into :distributors) + (values [{:did 23 :dname "Foo Distributors"}]) + (psqlh/on-conflict :did) + (psqlh/do-update-set! [:dname "EXCLUDED.dname || ' (formerly ' || distributors.dname || ')'"] [:downer "EXCLUDED.downer"]) + sql/format) +=> ["INSERT INTO distributors (did, dname) VALUES (23, ?) ON CONFLICT (did) DO UPDATE SET dname = ?, downer = ?" "Foo Distributors" "EXCLUDED.dname || ' (formerly ' || d.dname || ')'" "EXCLUDED.downer"] +``` ### insert into with alias `insert-into-as` can be used to write insert statements with table name aliased. From 3d2a85da8207f868a34ddb21214f4554ad723b6e Mon Sep 17 00:00:00 2001 From: Anton Oellerer Date: Tue, 8 Oct 2019 16:16:53 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index 3ddff47..a5cdea7 100644 --- a/README.md +++ b/README.md @@ -85,15 +85,6 @@ The query creation and usage is exactly the same as honeysql. sql/format) => ["INSERT INTO distributors (did, dname) VALUES (5, ?), (6, ?) ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname RETURNING *" "Gizmo Transglobal" "Associated Computing, Inc"] -(-> (insert-into :distributors) - (values [{:did 23 :dname "Foo Distributors"}]) - (psqlh/on-conflict :did) - (psqlh/do-update-set! [:dname "EXCLUDED.dname || ' (formerly ' || distributors.dname || ')'"]) - sql/format) -=> ["INSERT INTO distributors (did, dname) VALUES (23, ?) ON CONFLICT (did) DO UPDATE SET dname = ?" "Foo Distributors" "EXCLUDED.dname || ' (formerly ' || d.dname || ')'"] -``` -To set multiple fields on conflict, add the `[k, v]` statements like this: -```clj (-> (insert-into :distributors) (values [{:did 23 :dname "Foo Distributors"}]) (psqlh/on-conflict :did)