This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-11
Channels
- # architecture (1)
- # babashka (61)
- # babashka-sci-dev (1)
- # beginners (85)
- # calva (112)
- # clj-kondo (279)
- # cljdoc (16)
- # cljs-dev (15)
- # cljsrn (7)
- # clojure (168)
- # clojure-europe (36)
- # clojure-nl (10)
- # clojure-spec (6)
- # clojure-uk (5)
- # clojured (1)
- # clojurescript (20)
- # core-async (16)
- # crypto (2)
- # cursive (13)
- # datomic (25)
- # events (7)
- # fulcro (21)
- # google-cloud (3)
- # graalvm (2)
- # graalvm-mobile (2)
- # gratitude (3)
- # helix (20)
- # honeysql (4)
- # hugsql (15)
- # introduce-yourself (15)
- # leiningen (2)
- # lsp (24)
- # luminus (22)
- # malli (21)
- # meander (11)
- # midje (1)
- # other-languages (1)
- # pathom (8)
- # re-frame (5)
- # reagent (5)
- # releases (2)
- # reveal (1)
- # shadow-cljs (18)
- # spacemacs (17)
- # sql (9)
- # tools-build (12)
- # tools-deps (4)
- # vim (12)
Hi everyone. I’m fairly new to clojure and am trying to use a JSONB ?|
operator with hugsql. What I would like to do is pass a vector through as a param.
I’m seeing this error and I’m not sure how to use the vector appropriately in vector.
actual: org.postgresql.util.PSQLException: ERROR: operator does not exist: text < jsonb
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Thanks for any help in advance!
(sql/read-all-with-options tx {:org_id "org_test" :exclude_roles ["admin" "org_admin"]})
-- :name read-all-with-options :? :*
-- :doc get all users and filter out excluded roles
select * from users where org_id = :org_id
and (allowed_roles ??| ARRAY[ :exclude_roles ]) is false
Hey lukasz, unfortunately that didn’t work either.
actual: org.postgresql.util.PSQLException: ERROR: syntax error at or near "array"
`I tried logging what :exclude_roles is being passed as to the sql query by doing SELECT (:exclude_roles);
This is the response. Not sure if this is helpful:
({:?column? (apply_applicant ob_anon_primary)})
Ok, we didn't quite have the same query, but part of our system deals with typed arrays and jsonb so here's how you make it work:
select * from json_test where store->'foo' ??| :ids
and in your Clojure code you do: (query-ns/hugsql-query db {:ids (into-array ["qux"])})
where the table is defined as:
nomnom=# select * from json_test;
store
-------------------------
{"foo": ["abc", "def"]}
{"foo": ["qux", "def"]}
{"foo": ["abc", "zxc"]}
{"foo": ["qux", "zxc"]}
(4 rows)
nomnom=# \d json_test ;
Table "public.json_test"
Column | Type | Collation | Nullable | Default
--------+-------+-----------+----------+-------------
store | jsonb | | | '{}'::jsonb
So, in your example, you'd change ARRAY[:exclude_roles]
to just :exclude_roles
and when calling your query you'd write it as: (sql/read-all-with-options tx {:org_id "org_test" :exclude_roles (into-array ["admin" "org_admin"])})
Thanks so much, sorry I’m new to clojure, where do I put this?
(query-ns/hugsql-query db {:ids (into-array ["qux"])})
Hopefully this is more readable : https://gist.github.com/lukaszkorecki/25cfa180b421fe269617b062463008fb