How might I do an expression such as this in honesql (request_end and request_begin are columns):
avg((request_end - request_begin) / 1000.0) as avg_exec_time[:- :request_end :request_begin] for the subtraction...
[:/ ... 1000.0] for the divide...
[:avg ...] for the function call...
[... :avg_exec_time] for the alias
And then I assume you want to use it in a SELECT?
{:select [ expr expr expr ... ] ...} so putting that all together you get:
{:select [[[:avg [:/ [:- :request_end :request_begin] 1000.0]] :avg_exec_time] ...] ...}
depending on whether you need to select a second or subsequent expression...If the documentation can make this clearer, let me know.
Cool! I’ll give that a shot. I think the main thing is just knowing where to look. Thanks!
The Getting Started page has these examples:
https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1045/doc/getting-started
Ah, I thought I was doing the above but it’s the nested brackets that got me originally. I was doing:
(hsql/format
{:select [[:- :request_end :request_begin]]
:from [:foo]})
but need to do:
(hsql/format
{:select [[[:- :request_end :request_begin] :diff]]
:from [:foo]})
Once I got it, it makes sense that you need to add the extra nesting to capture the expression and the alias.
If I get some time maybe I’ll put together a doc PR.Thanks for the clarification!