This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-15
Channels
- # announcements (8)
- # architecture (9)
- # autochrome-github (1)
- # babashka (48)
- # beginners (55)
- # calva (36)
- # cider (16)
- # clj-commons (1)
- # clj-kondo (38)
- # cljs-dev (44)
- # cljsrn (1)
- # clojure (164)
- # clojure-europe (35)
- # clojure-nl (2)
- # clojure-norway (10)
- # clojure-uk (23)
- # clojurescript (50)
- # conjure (24)
- # core-async (1)
- # cryogen (2)
- # cursive (38)
- # datalevin (11)
- # datascript (2)
- # datomic (13)
- # duct (1)
- # emacs (16)
- # events (12)
- # exercism (3)
- # figwheel-main (7)
- # fulcro (26)
- # honeysql (5)
- # integrant (1)
- # jobs (3)
- # kaocha (6)
- # lsp (72)
- # malli (22)
- # nextjournal (35)
- # nrepl (1)
- # off-topic (34)
- # pathom (5)
- # polylith (8)
- # portal (40)
- # re-frame (14)
- # reagent (42)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # reveal (9)
- # sci (2)
- # shadow-cljs (13)
- # sql (3)
- # tools-deps (33)
- # vim (25)
i’m trying to write this query:
SELECT c.id, c.name,
JSONB_AGG(JSONB_BUILD_OBJECT('id', ce.expertise_id,
'years', ce.experience_years)) AS "expertises"
FROM candidates AS C
LEFT JOIN candidate_expertises AS ce ON c.id = ce.candidate_id
GROUP BY c.id
as
.. (:require [honey.sql :as sql2]
[honey.sql.helpers :as sqlh2])..
(-> (sqlh2/select
:c.id
:c.name
[[:jsonb_agg [:jsonb_build_object
"id" :ce.expertise_id
"experience_years" :ce.experience_years]] "expertises"]
)
(sqlh2/from [:candidates :c])
(sqlh2/left-join [:candidate-expertises :ce] [:= :c.id :ce.candidate-id])
(sqlh2/group-by :c.id))
sql/format
returns
["SELECT c.id, c.name,
JSONB_AGG(JSONB_BUILD_OBJECT(?, ce.expertise_id, ?, ce.experience_years)) AS \"expertises\"
FROM candidates AS c
LEFT JOIN candidate_expertises AS ce ON c.id = ce.candidate_id
GROUP BY c.id"
"id"
"experience_years"]
and execute
throws this error:
Assert failed: Alias should have two parts[:jsonb_build_object "id"
:ce.expertise_id "experience_years" :ce.experience_years] (= 2 (count x))
and i’m lost :)solved it: i used our helper for execute
, which called format
from honey v1 🙃
but i still want to figure out if it’s possible to solve this with honey v1.0.461
:
.. (:require [honeysql.core :as sql] [honeysql.helpers :as sqlh]) ..
(-> (sqlh/select
:c.id
:c.name
[[:jsonb_agg [:jsonb_build_object
"id" :ce.expertise_id
"experience_years" :ce.experience_years]] "expertises"]
)
(sqlh/from [:candidates :c])
(sqlh/left-join [:candidate-expertises :ce] [:= :c.id :ce.candidate-id])
(sqlh/group :c.id)
(sql/format))
throws the same exception as aboveIn v1, you almost certainly need sql/call to identify the function calls in the select.
thanks a lot, Sean! it seems to be working with:
..
[(sql/call
"jsonb_agg"
(sql/call "jsonb_build_object"
"id" :ce.expertise_id
"years" :ce.experience_years)) "expertises"] ..
1