Fork me on GitHub
#sql
<
2023-03-29
>
lepistane12:03:52

How does one convert this query to hugSQL?

(SELECT '2023-01-02' + INTERVAL 1 DAY)
I tried
(next.jdbc/execute! (honey.sql/format {:select ["2023-01-02"]
                                              :from [:+ :interval :1 :day]}))
but it doesn't work
class clojure.lang.PersistentVector cannot be cast to class clojure.lang.IPersistentMap

Felipe12:03:19

maybe

(honey.sql/format {:select [[[:+ "2023-01-02" [:interval 1 :day]]]]}
                    {:inline true})
  ;; => ["SELECT '2023-01-02' + INTERVAL 1 DAY"]

lepistane13:03:17

that's interesting... Thanks a lot

seancorfield15:03:02

The docs talk about :select needing extra nesting for expressions because it's:

:select [:col [:col :alias] [[:expr] :alias] [[:expr]]]
;=> SELECT col, col AS alias, EXPR() AS alias, EXPR()
So if you have just an expression, it's :select [[[:expr]]]