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 fooI 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 fooIf 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
Same as with :select.
SQL partition-by allows aliases? I’m not sure what that would mean
It probably doesn't, but I believe that vector nesting is handled in a generic way.
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 fooNot 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