diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e53685..6b4a860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 2.3.next in progress + * Address [#414](https://github.com/seancorfield/honeysql/issues/414) by providing an example of `ORDER BY` with a `CASE` expression. * Address [#412](https://github.com/seancorfield/honeysql/issues/412) by documenting options in a separate page and reorganizing the ToC structure. * Address [#409](https://github.com/seancorfield/honeysql/issues/409) by making docstring check for public helpers conditional. * Address [#401](https://github.com/seancorfield/honeysql/issues/401) by adding `register-dialect!` and `get-dialect`, and also making `add-clause-before`, `strop`, and `upper-case` public so that new dialects are easier to construct. diff --git a/doc/clause-reference.md b/doc/clause-reference.md index bee45b9..ab1d816 100644 --- a/doc/clause-reference.md +++ b/doc/clause-reference.md @@ -815,6 +815,12 @@ user=> (sql/format {:select [:*] :from :table ;; expression without direction is still wrapped: :order-by [:status, [[:year :created-date]]]}) ["SELECT * FROM table ORDER BY status ASC, YEAR(created_date) ASC"] +;; a more complex order by with case (and direction): +user=> (sql/format {:select [:*] :from :table + :order-by [[[:case [:< [:now] :expiry-date] + :created-date :else :expiry-date] + :desc]]}) +["SELECT * FROM table ORDER BY CASE WHEN NOW() < expiry_date THEN created_date ELSE expiry_date END DESC"] ``` ## limit, offset, fetch