Scala 将数组作为参数传递给 Postgres jdbc sql 语句



我正在尝试使用以下代码将数组传递给SQL查询的预准备语句

val arr = Array("id1", "id2", "id3")
val sqlArr = connection.createArrayOf("varchar", arr.toArray)
stmt.setArray(1, sqlArr)
stmt.executeQuery()

我收到此错误,

ERROR: operator does not exist: character varying = character varying[]
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.

我正在使用的SQL查询

select col1, col2 from someTable where col3 in (?) and col4 != 'no';

我还尝试将参数类型更改为VARCHARtext

当我打印准备好的语句时,它看起来像这样。

select col1, col2 from someTable where col3 in ('{"id1", "id2", "id3"}') and col4 != 'no';

我遇到了麻烦,关于如何进行,任何帮助将不胜感激

我正在使用 scala 2.12

在SQL查询中将in更改为any =对我来说是有效的。

最新更新