This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-17
Channels
- # announcements (7)
- # babashka (24)
- # beginners (11)
- # boot (16)
- # calva (46)
- # cider (5)
- # clara (3)
- # clj-kondo (2)
- # cljfx (5)
- # clojure (122)
- # clojure-brasil (26)
- # clojure-dev (20)
- # clojure-europe (20)
- # clojure-germany (1)
- # clojure-nl (1)
- # clojure-norway (54)
- # clojure-uk (2)
- # clojurescript (6)
- # core-matrix (23)
- # datomic (85)
- # graalvm (1)
- # honeysql (9)
- # hyperfiddle (31)
- # lsp (3)
- # malli (9)
- # nbb (2)
- # off-topic (15)
- # pathom (15)
- # pedestal (4)
- # polylith (5)
- # re-frame (5)
- # reitit (9)
- # releases (2)
- # shadow-cljs (63)
- # specter (4)
- # xtdb (7)
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!