hey folks 👋:skin-tone-2: big fan of HoneySQL! most sensible way to write SQL in Clojure in my opinion 😄
anyone know how I can get honeysql to output something like this:
SELECT CURRENT DATE - 1 DAY FROM sysibm.sysdummy1
?
I would probably just do {:select [(sql/raw "CURRENT DATE - 1 DAY")] :from [:sysibm.sysdummy1]}
.
I shied away from sql/raw
for a while, but I find that it often makes expressions like this more readable.
I do something similar [:<= :created (sql/raw ["now() - interval '3 months'"])]
If you do have functions, you can do this (select :jdoc_id [(sql/call :to_char :created "YYYY-MM-DD HH24:MI:SS") :created])
which renders as select jdoc_id, to_char(created, ?) as created....
where YYYY-MM-DD HH24:MI:SS
is passed in as a parameter.
thanks, #sql/raw
does the trick!
@plexus Which DB is that? I'd be happy to support it better via dialects in HoneySQL v2 if it makes sense to do so...
yes, Db2 on AS/400 ... pretty gnarly client project 🙂
FYI, two possible ways to do this in v2
user=> (-> (select [[:inline [:current-date :- 1 :day]]]) (from :table) (h/format))
["SELECT CURRENT DATE - 1 DAY FROM table"]
user=> (-> (select [[:- [:raw "CURRENT DATE"] [:inline [1 :day]]]]) (from :table) (h/format))
["SELECT CURRENT DATE - 1 DAY FROM table"]
user=>
(the exact syntax is still a bit up in the air right now)I believe it's DB2
Thanks. Will read up and see what's what with that.