Fork me on GitHub
#sql
<
2017-04-21
>
owen15:04:13

does anyone know how to do functions with multiple arguments in honeysql in the edn representation? trying to get group_concat specifically which takes a separator and field

owen15:04:22

{:select [:pair :%count.pair]
               :from [[{:select [:name
                                 [[:%GROUP_CONCAT.name,x] :B]]
                        :from [:order_items]
                        :group-by [:order_id]}]]
               :group-by [:pair]}

tanzoniteblack16:04:53

@owen if you use the helper function call instead off the :%... form, you can do it: (honeysql/call :group_concat :name x)

tanzoniteblack16:04:44

the EDN only form of that translates out to #honeysql/call [:foo :bar] , which requires the reader to have access to the reffed namespace

tanzoniteblack16:04:33

and is not something I would recommend relying on, because now you're dependent on making sure the reader loads namespaces like you expect when interpretting edn...which is something that I've always just found difficult and avoid

owen16:04:19

hmm I'm kindof constrained to using the pure edn version, we are definining hundreds of queries within a .edn file used by analysts to no clojure

owen16:04:42

I think I found a way using the defmethod/fn-handler though to write my own interpretation of GROUP_CONCAT

owen16:04:45

thank you though!

tanzoniteblack16:04:10

any reason you can't just write the raw SQL queries with ? forms for args?

owen16:04:24

the edn are getting transformed

donaldball16:04:32

You can always be explicit about the tag literal readers you require when reading edn fwiw

donaldball16:04:50

Maybe even s/can/should/

owen16:04:14

this is the first point where there's something I cant seem to get honeysql to generate for me

donaldball16:04:25

(edn/read-string {:readers {'sql/call honeysql.types/read-sql-call}} s) or similar should do you if you like the #sql/call reader literal