Fork me on GitHub
#honeysql
<
2021-02-22
>
seancorfield19:02:09

In case anyone missed this in #announcements

👍 9
devn22:02:32

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! ...))

devn22:02:09

i may just rename the column, but im curious if anyone has any bright ideas

seancorfield23:02:07

HoneySQL can do quoting for different databases: it's an option to hsql/format

seancorfield23:02:15

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).

seancorfield23:02:28

^ @devn does that solve your problem?

devn23:02:08

unfortunately, no. I tried that.

devn23:02:27

it’s alright, I went ahead and renamed the column

seancorfield23:02:48

Which version of HoneySQL are you using?

devn23:02:24

actually, you know what, let me try one more time because i see you have :quoting :ansi bare there (with no wrapping {})

devn23:02:53

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

seancorfield23:02:39

I realized you must be using 1.0 and the honeysql-postgres extension lib -- :upsert 🙂

seancorfield23:02:07

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=> 

devn23:02:29

[honeysql "1.0.444"]
                 [nilenso/honeysql-postgres "0.2.6"]

devn23:02:38

ah, nice!

devn23:02:56

then /that/ is what i’ll do to finish out my day 🙂

seancorfield23:02:59

Also, since you're on 1.0, make sure you update to 1.0.461 for the important bug fix.

devn23:02:09

yep, saw that

seancorfield23:02:01

You can use 1.0 and 2.0 side-by-side and migrate piecemeal: different maven coords and different namespaces 🙂

devn23:02:15

:male-cook: 💋 🤌

👍 3