From 4f2f7af697ef47caf7987e918183b14efabccfc3 Mon Sep 17 00:00:00 2001 From: KgOfHedgehogs Date: Mon, 18 Feb 2019 13:43:14 +0200 Subject: [PATCH] upsert with modify example bug Result of the example `["INSERT INTO distributors (did, dname) VALUES (23, ?) ON CONFLICT (did) DO UPDATE SET dname = ?" "Foo Distributors" "EXCLUDED.dname || ' (formerly ' || d.dname || ')'"]` Will make dname set to varchar value which is exactly `"EXCLUDED.dname || ' (formerly ' || d.dname || ')'"` string, without value substitutions and concatenation being called. Need to use `sql/call` with `:CONCAT` (`:||` for some reason not added to `honeysql.format/infix-fns` maybe there is need to extend it in honeysql-postgres?) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0bc72c1..c5b0bd7 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,9 @@ The query creation and usage is exactly the same as honeysql. (-> (insert-into :distributors) (values [{:did 23 :dname "Foo Distributors"}]) (psqlh/on-conflict :did) - (psqlh/do-update-set! [:dname "EXCLUDED.dname || ' (formerly ' || distributors.dname || ')'"]) + (psqlh/do-update-set! [:dname (sql/call :CONCAT :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 || ')'"] +=> ["INSERT INTO distributors (did, dname) VALUES (?, ?) ON CONFLICT (did) DO UPDATE SET dname = CONCAT(EXCLUDED.dname, ?, distributors.dname, ?)" 23 "Foo Distributors" " (formerly " ")"] ``` ### insert into with alias