This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-15
Channels
- # announcements (3)
- # aws (2)
- # babashka (57)
- # beginners (24)
- # clj-kondo (5)
- # clj-together (3)
- # cljs-dev (11)
- # clojure (83)
- # clojure-australia (1)
- # clojure-china (1)
- # clojure-europe (32)
- # clojure-filipino (1)
- # clojure-hk (5)
- # clojure-indonesia (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-sg (1)
- # clojure-spain (1)
- # clojure-taiwan (1)
- # clojure-uk (2)
- # clojurescript (7)
- # conjure (36)
- # data-science (19)
- # datomic (27)
- # emacs (44)
- # events (4)
- # fulcro (16)
- # honeysql (6)
- # inf-clojure (1)
- # interop (5)
- # malli (5)
- # nbb (1)
- # off-topic (19)
- # pathom (4)
- # practicalli (1)
- # remote-jobs (4)
- # ring (1)
- # shadow-cljs (72)
- # spacemacs (2)
Hi! Is it possible to use case
in order-by
? I tried this and it outputs weird results
(sql2/format {:select [:*]
:from :my-table
:order-by [:case [:= :a 1] :a :else :b]})
=> ["SELECT * FROM my_table ORDER BY case ASC, = A, a ASC, else ASC, b ASC"]
I also tried wrapping case
to extra set of []
but that throws an exception that it's expecting a keyword.I'm trying to sort conditionally by different fields. This is supported at least in postgres
Maybe the question is how do I tell that case
is an expression and not a column :thinking_face:
I'm on vacation today but if you create an issue on GH with details, I'll try to take a look this weekend and either add a solution to the issues (and docs) or turn it into an enhancement to be added.
Thanks Sean! I created an issue https://github.com/seancorfield/honeysql/issues/414 Have a nice vacation! 😎
Just in case anyone needs to know the answer, without having to read the GH issue:
user=> (sql/format {:select [:*]
#_=> :from :my-table
#_=> :order-by [[[:case [:= :field_x 1] :field_y :else :field_z]]]})
["SELECT * FROM my_table ORDER BY CASE WHEN field_x = ? THEN field_y ELSE field_z END ASC" 1]
user=>
and I'm updating the docs to include that example for :order-by
Just in case anyone needs to know the answer, without having to read the GH issue:
user=> (sql/format {:select [:*]
#_=> :from :my-table
#_=> :order-by [[[:case [:= :field_x 1] :field_y :else :field_z]]]})
["SELECT * FROM my_table ORDER BY CASE WHEN field_x = ? THEN field_y ELSE field_z END ASC" 1]
user=>
and I'm updating the docs to include that example for :order-by