Hi folks, how would you generate "select 1 < 2" with honeysql? I'd have expected it to be {:select [:< 1 2]}
but that yields ["SELECT <, ?, ?" 1 2]
.
@cddr I'm pretty sure for something like that you'd need the sql/raw
function? {:select (sql/raw "1 < 2")}
(where sql
is an alias for honeysql.core
)
I think you could also do {:select #sql/raw "1 < 2"}
-- I believe there's a data reader for that...?
Cool. Thanks
{:select [(honeysql.core/call :< 1 2)]}
honeysql.core/call is used to invoke SQL functions. The first argument is the function name as a keyword
@bja call
will substitute parameters
(format (select (call :< 1 2)))
=> ["SELECT ? < ?" 1 2]
even with brackets and the raw map
(format {:select [(call :< 1 2)]})
=> ["SELECT ? < ?" 1 2]
raw
works
(format {:select [#sql/raw "1 < 2"]})
=> ["SELECT 1 < 2"]
but it's kinda ugly (I assume this is part of a larger query @cddr?)Yeah. Surprised I haven't run into this before
I think older versions of HoneySQL did not lift parameters in some situations -- but that was a bug.
So you may have gotten away with it on older versions 🙂