This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-16
Channels
- # announcements (3)
- # babashka (48)
- # beginners (35)
- # calva (3)
- # chlorine-clover (5)
- # clj-kondo (9)
- # cljdoc (20)
- # cljsrn (1)
- # clojure (55)
- # clojure-europe (33)
- # clojure-nl (3)
- # clojure-norway (6)
- # clojure-spec (7)
- # clojure-uk (27)
- # clojurescript (95)
- # closh (1)
- # conjure (1)
- # cursive (16)
- # datomic (30)
- # emacs (7)
- # honeysql (1)
- # hugsql (2)
- # introduce-yourself (2)
- # jobs (1)
- # lsp (30)
- # malli (22)
- # nbb (11)
- # news-and-articles (1)
- # off-topic (8)
- # pathom (21)
- # polylith (39)
- # portal (4)
- # practicalli (4)
- # protojure (1)
- # re-frame (14)
- # releases (1)
- # restql (1)
- # reveal (24)
- # sci (1)
- # sql (21)
- # vim (11)
- # xtdb (33)
hello folks, when using seancorfield/next.jdbc
, how do you make a parameterized query that uses IN
?
with others you need to do it explicitly for the array conversion - maybe by extending settable parameter to vectors
https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.689/doc/getting-started/tips-tricks
otherwise you need to produce the IN (?, ?, ?, ?, ...)
- probably via generating the query with honeysql
As some background, it's probably worth pointing out that next.jdbc
(and clojure.java.jdbc
before it) are thin wrappers over JDBC: you give it SQL and parameters, it hands it off to JDBC and gives you back results (either as Clojure data or as a reducible). There's no "formatting" of SQL and no translation beyond what JDBC itself allows. HoneySQL, on the other hand, is all about generating SQL but it has no insight into JDBC or SQL data types (or even what constitutes valid SQL).
@emccue I'm using Postgres, and by playgin with HoneySQL on top, I see I would have to manually spread the query to look like ["SELECT * FROM table WHERE table_id IN (?, ?, ?)" 1 2 3)]
(this is what I see HoneySQL doing)
humm, but now I note you used a standard array, I haven't tried that
the previous way should work, but it'll run up against PG param count limits (smallint so like 32k or so parameters)
the field type in an UUID, if I sent the items on the list as UUID's it complains, but if I convert to strings it complains for a different reason
PGobject toInsertUUID = new PGobject();
toInsertUUID.setType("uuid");
toInsertUUID.setValue(uuid.toString());
PreparedStmt stmt = conn.prepareStatement(query);
stmt.setObject(placeHolder,toInsertUUID);
stmt.execute();
@emccue I found an example that shows we have to use a typed array with the UUID type for that to work