【问题标题】:Scala pass array as parameter to Postgres jdbc sql statementScala将数组作为参数传递给Postgres jdbc sql语句
【发布时间】:2023-03-24 17:49:01
【问题描述】:

我正在尝试使用以下代码将数组传递给 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

【问题讨论】:

  • 会建议看看anorm 而不是原始的JDBC

标签: scala playframework postgresql-9.1


【解决方案1】:

将 sql 查询中的 in 更改为 any = 对我有用。

【讨论】:

    猜你喜欢
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 2011-08-07
    • 2015-04-25
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    相关资源
    最近更新 更多