我的代码:
def function1(userId: Long) = DB withConnection {
implicit con =>
val res = SQL(
"""
SELECT my_custom_function({userId}, {param2}) as "my_title"
"""
).on('userId -> userId,
'param2 -> Array(Statuses.paid.id, Statuses.pending.id))
.as(SqlParser.get[Option[Long]]("my_title").single) //error
if (res.isDefined) res.get
else 0L
}
my_custom_function
返回 Long
或 BigInt
。
此代码抛出错误 [PSQLException: Can't infer the SQL type to use for an instance of [I.使用带有显式类型值的 setObject() 来指定要使用的类型。]
这是怎么回事?
最佳答案
我认为问题是数组参数。最新的 Anorm 防止了可能导致这种情况的不安全参数转换。您可以使用 Anorm 快照进行尝试。
关于postgresql - 无法为返回 BigInt 的用户定义函数推断 SQL 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21262123/