Hello all, I was working on converting the following to honey-sql and came across some interesting behavior.
SELECT AVG(column_1) OVER first_window AS avg_col_1,
AVG(column_2) OVER second_window AS avg_col_2
FROM some_table
WINDOW first_window AS (PARTITION BY some_other_column_1),
second_window AS (PARTITION BY some_other_column_2)
First attempt, with a single window declaration:
(-> {:select [[[:over
[[:avg :column_1] :first_window :avg_col_1]
[[:avg :column_2] :second_window :avg_col_2]]]],
:from [:some_table]}
(sql/window :first_window (sql/parition-by :some_other_column_1))
(honey/format)
)
;;==> WORKS AS EXPECTED
Second attempt, with a second window declaration:
(-> {:select [[[:over
[[:avg :column_1] :first_window :avg_col_1]
[[:avg :column_2] :second_window :avg_col_2]]]],
:from [:some_table]}
(sql/window :first_window (sql/partition-by :some_other_column_1))
(sql/window :second_window (sql/partition-by :some_other_column_2))
(honey/format)
)
;;==> execution error (exceptioninfo) at honey.sql/format-item-selection (sql.cljc:592).
;; illegal syntax in select expression
I've tried adding more [] and [:raw ] , but it seems to not appreciate multiple window clauses.
Thanks for any help that can be given!It's a bug. Thanks for catching it. https://github.com/seancorfield/honeysql/issues/551 There will be a new SNAPSHOT containing the fix shortly.
Thanks Sean
2.6.9999-SNAPSHOT is available on Clojars. Or you can try it via git deps. Not quite sure yet when the next release will get cut.
Just tried it out using 2.6.9999-SNAPSHOT, thanks for jumping on this so quickly!