This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-03
Channels
- # announcements (5)
- # babashka (8)
- # beginners (98)
- # biff (2)
- # calva (20)
- # cider (16)
- # clerk (2)
- # clj-kondo (20)
- # cljdoc (19)
- # clojure (90)
- # clojure-art (3)
- # clojure-boston (1)
- # clojure-europe (7)
- # clojure-nl (2)
- # clojure-norway (47)
- # clojure-uk (3)
- # clojurescript (10)
- # cursive (10)
- # data-science (1)
- # datalevin (1)
- # defnpodcast (1)
- # events (2)
- # fulcro (11)
- # gratitude (2)
- # honeysql (18)
- # hyperfiddle (11)
- # introduce-yourself (1)
- # jobs (2)
- # lambdaisland (4)
- # lsp (6)
- # malli (4)
- # membrane (3)
- # off-topic (58)
- # polylith (14)
- # portal (2)
- # releases (2)
- # ring-swagger (4)
- # tools-deps (8)
- # xtdb (8)
How can I build a where clause that involves the @?
operator for jsonb path? What I'm doing is:
(sql/register-op! (keyword "@?"))
(sql/format [(keyword "@?")
:entity
"$.foo.bar[*].id ? (@ == 42)"]
{:numbered true})
["entity @?? $1" "$.foo.bar[*].id ? (@ == 42)"]
But I'm getting @??
for some reason. Is it because of extra quoting of question marks or something?Have you seen https://cljdoc.org/d/com.github.seancorfield/honeysql/2.6.1126/api/honey.sql.pg-ops#at??
Could be down to what you pass into sql/format
- that's not a valid honeysql query I think. Try using it in a valid query
It still doesn't work for me:
(sql/format {:select 42 :where [:and [honey.sql.pg-ops/at? "aa" "bb"]]})
["SELECT ? WHERE (? @?? ?)" 42 "aa" "bb"]
:@?
(or for that matter any keyword that starts with @ ) isn't really valid it just happens to work sometimes 😞
i've never used jsonb through honeysql but if you can use string operators that should be way safer
sorry @UAEH11THP what do you mean by "string operators"?
There's always :raw
if you need it https://cljdoc.org/d/com.github.seancorfield/honeysql/2.6.1126/doc/getting-started/sql-special-syntax-?q=%3Araw#raw
Yeah I'm trying to build a raw expression. But I don't want to put the jsonpath inline. It might lead to injections.
Seems :raw
still supports params though:
(sql/format {:select [:a [[:raw ["@var := " ["foo"]]]]]})
;;=> ["SELECT a, @var := (?)" "foo"]
option one with params
(sql/format {:select [:a [[:raw ["entity @? " [:param :path]]]]]}
{:numbered true
:params {:path "$.foo.bar"}})
option two with inline
(sql/format [:raw "entity @?" \space [:inline "$.foo.bar[*].id ? (@ == 42)"]])
["entity @? '$.foo.bar[*].id ? (@ == 42)'"]
FWIW I myself would probably use jsonb_path_exists
with silent
set to TRUE
till the issue with @?
(and, seemingly, any ops containing ?
) is fixed.
well, the jsonb_path_*
functions do not work with my index which is USING GIN (entity jsonb_path_ops)
I was under the impression that all SQL dialects always treated ??
as an escaped ?
and therefore @??
was correct (since I don't use PostgreSQL). Thanks for the issue -- will get it addressed shortly.