1

I'm trying to pass an array of strings to a select statement and I keep getting the error:

 org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. Use setObject() with an explicit Types value to specify the type to use.

I know that the column type is correct, it looks as if passing a vector is the culprit. What is the correct way to do this?

The sql statement is formatted like so:

"SELECT * FROM said_table WHERE item_id IN (?)"

1
  • perhaps show your code Commented Jan 20, 2015 at 21:37

1 Answer 1

1

This answer assumes you are using jdbc and not korma or something like it and need to generate the sql directly instead of going through some tool:

the in directive requires you to crate one ? for each item in the list. I end up using this pattern when something else requires me to build the SQL manually:

(let [placeholders (s/join ", " (repeat (count things-go-here) "?"))
      query "SELECT * FROM said_table WHERE item_id IN (%s)"]
    (exec-raw [(format query placeholders) things-go-here] :results)
    ....)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.