Fork me on GitHub
#sql
<
2023-08-18
>
Jacob Emcken19:08:37

I am looking for an example (if it is possible) where I can use a WHERE type IN ? filter in SQL and give it a Clojure set (e.g. #{"type1" "type2"} ) is this possible? I seem to be getting: ; Can't infer the SQL type to use for an instance of clojure.lang.PersistentHashSet. Use setObject() with an explicit Types value to specify the type to use.

seancorfield19:08:44

Some databases allow a Java array to be passed as an IN parameter in JDBC but not all. Some require that you explicit "hint" the parameter type (see https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.883/api/next.jdbc.types for those hinting functions). If you want a more flexible way to build your SQL that understands Clojure data structures, use HoneySQL which will construct the appropriate WHERE x IN (?,?,?) from a Clojure sequence (I think it will still require you specify (seq your-set) since it requires sequential data and a set is not sequential).

Jacob Emcken20:08:20

I am using Postgres... I'll look into the link at a later time when I'm not as tired. Thanks for the pointers 🙏