0

I am using postgres DB. I want to pass the list of ids in IN clause. The type of column is int8. I have list of Long in the code.

This is the code

I am getting below exception : Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = bigint[] Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.

I tried using converting to String array and using varchar. But none of that works. Any reference would be helpful.

Tejas Joshi
  • 197
  • 3
  • 12
  • String sql = "select id, name from table where id in (?::int8[])"; Array sqlArray = con.createArrayOf("bigint", ids.toArray(new Long[ids.size()])); ps.setArray(1, sqlArray); – Tejas Joshi May 14 '19 at 10:54
  • This is a tough one to handle in Java. Perhaps the best you can do is to have a fixed number of parameters, e.g. for three use `WHERE col IN (?, ?, ?)`. – Tim Biegeleisen May 14 '19 at 10:56
  • The list is being passed from upstream and I can't update the sql easily as it is tightly coupled with another module. – Tejas Joshi May 14 '19 at 10:58
  • Change your query to `select id, name from table where id = any (?)`. Everything else seems fine. – coladict May 15 '19 at 07:52

0 Answers0