This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-22
Channels
- # announcements (10)
- # babashka (40)
- # beginners (192)
- # calva (9)
- # cider (2)
- # clj-kondo (9)
- # clojure (69)
- # clojure-dev (15)
- # clojure-europe (29)
- # clojure-gamedev (6)
- # clojure-italy (2)
- # clojure-nl (41)
- # clojure-spec (49)
- # clojure-uk (11)
- # clojurescript (68)
- # conjure (1)
- # cryogen (20)
- # cursive (37)
- # data-oriented-programming (10)
- # data-science (4)
- # datahike (7)
- # datomic (8)
- # depstar (14)
- # emacs (7)
- # events (2)
- # figwheel-main (1)
- # fulcro (81)
- # honeysql (22)
- # hugsql (5)
- # juxt (3)
- # leiningen (8)
- # lsp (314)
- # malli (20)
- # meander (15)
- # membrane (20)
- # mid-cities-meetup (11)
- # practicalli (2)
- # reagent (2)
- # remote-jobs (2)
- # ring-swagger (1)
- # rum (3)
- # sci (21)
- # shadow-cljs (52)
- # startup-in-a-month (1)
- # testing (9)
- # tools-deps (41)
- # vim (8)
- # xtdb (4)
I am using honeysql to generate a suffix which I then pass into sql.builder/for-insert-multi
as an option.
The trouble is that the suffix has a param named group
, which needs to be quoted, otherwise PG is unhappy.
Roughly it goes something like this:
(let [suffix (first (hsql/format {:upsert {:on-conflict [:id] :do-update-set [:a :group :b]}}))
insert-multi (sql.builder/for-insert-multi table cols rows {:suffix suffix :column-fn (fn [col] (format "\"%s\"" col))})]
(jdbc/execute! ...))
HoneySQL can do quoting for different databases: it's an option to hsql/format
If you're still using HoneySQL 1.0 or earlier: (hsql/format .. :quoting :ansi)
If you're already using HoneySQL 2.0: (hsql/format .. {:quoted true})
(the ANSI dialect is the default).
^ @devn does that solve your problem?
Which version of HoneySQL are you using?
actually, you know what, let me try one more time because i see you have :quoting :ansi bare there (with no wrapping {})
ah yes, that’ll do it — however it still is a bit of a mess to also add in the column-fn transformation. if we run into another instance of this i’ll consider switching it up
I realized you must be using 1.0 and the honeysql-postgres extension lib -- :upsert
🙂
In 2.0, you don't need the extension lib and it's just
user=> (sql/format
#_=> {:on-conflict [:id] :do-update-set [:a :group :b]} {:quoted true})
["ON CONFLICT (\"id\") DO UPDATE SET \"a\" = EXCLUDED.\"a\", \"group\" = EXCLUDED.\"group\", \"b\" = EXCLUDED.\"b\""]
user=>
Also, since you're on 1.0, make sure you update to 1.0.461 for the important bug fix.
You can use 1.0 and 2.0 side-by-side and migrate piecemeal: different maven coords and different namespaces 🙂