honeysql

plooney 2024-11-18T22:28:50.301749Z

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!

👍 1
seancorfield 2024-11-18T23:03:03.897209Z

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.

👍 1
plooney 2024-11-18T23:06:13.012169Z

Thanks Sean

seancorfield 2024-11-18T23:13:19.600539Z

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.

👍 1
plooney 2024-11-19T16:20:10.859239Z

Just tried it out using 2.6.9999-SNAPSHOT, thanks for jumping on this so quickly!

👍🏻 1
2024-11-18T22:57:16.488659Z

2024-11-18T23:04:09.732819Z