This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-31
Channels
- # announcements (5)
- # babashka (5)
- # beginners (24)
- # calva (21)
- # cherry (1)
- # clerk (20)
- # clj-kondo (3)
- # clj-otel (12)
- # clojure (50)
- # clojure-austin (2)
- # clojure-conj (3)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (203)
- # clojure-spec (3)
- # clojure-uk (6)
- # clojurescript (8)
- # conjure (1)
- # datomic (1)
- # deps-new (1)
- # emacs (5)
- # graphql (8)
- # gratitude (5)
- # holy-lambda (16)
- # honeysql (18)
- # hyperfiddle (12)
- # java (1)
- # jobs (1)
- # lsp (24)
- # membrane (8)
- # nbb (1)
- # off-topic (19)
- # portal (28)
- # proletarian (11)
- # rdf (63)
- # re-frame (38)
- # reagent (8)
- # reitit (1)
- # releases (6)
- # remote-jobs (1)
- # scittle (4)
- # shadow-cljs (20)
- # spacemacs (4)
- # sql (7)
- # transit (1)
I think I found a bug in honey’s formatting of partition-by
(-> {:select [[[:over [[:lead :event]
{:partition-by [[:upper :a]]}]]
:random]]
:from [[:foo :foo]]}
(honey.sql/format)
(first))
produces SELECT LEAD(event) OVER (PARTITION BY upper a) AS random FROM foo AS foo
I expected the partition by to be PARTITION BY UPPER(a)
this honey produces the correct result
(-> {:select [[[:over [[:lead :event]
{:partition-by [[[:upper :a]]]}]]
:random]]
:from [[:foo :foo]]}
(honey.sql/format)
(first))
SELECT LEAD(event) OVER (PARTITION BY UPPER(a)) AS random FROM foo AS foo
If this is not user error, I’ll open an issue
Pretty sure it's user error as :partition-by
can accept many columns.
Zero nesting, a single keyword - a single column
One level of nesting - >= 1 columns
Two levels - same but with aliases
Three levels - same but with function calls
SQL partition-by allows aliases? I’m not sure what that would mean
that would make sense. If that’s the case, I contend it’s a bug but, of course, Sean is arbiter 🙂
btw
(-> {:select [[[:over [[:lead :event]
{:partition-by [[[:upper :a] :A]]}]]
:random]]
:from [[:foo :foo]]}
(honey.sql/format)
(first))
produces SELECT LEAD(event) OVER (PARTITION BY UPPER(a) A) AS random FROM foo AS foo
Not a bug. Portions of HoneySQL are generic, just to keep maintenance manageable (because SQL is so f***ing complex) -- and there are many, many ways to persuade HoneySQL to generate invalid SQL 🙂
Understood
So, just double wrap functions in the partition by clause?
Exactly like select, yes.
This is documented, BTW:
> :partition-by
accepts the same arguments as :select
above (even though the allowable SQL generated is much more restrictive).
From https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.1011/doc/getting-started/sql-clause-reference#window-partition-by-and-over
I should have RTFM. Thanks!
All of the following are formatted like SELECT:
:select #'format-selects
:select-distinct #'format-selects
:select-distinct-on #'format-selects-on
:delete (check-where #'format-selects)
:from #'format-selects
:using #'format-selects
:cross-join #'format-selects
:partition-by #'format-selects
:returning #'format-selects