例如我创建函数,只需通过id和/或电子邮件查找用户(解析结果在此问题中没有意义):
def getFullUser(userId: Option[Long] = None, email: Option[String] = None) {
DB.withConnection { implicit c =>
val userRow = SQL(
"""
SELECT *
FROM t_users
WHERE
id = COALESCE({userId}, id) and
email = COALESCE({email}, email)
""").on('userId -> userId, 'email -> email).apply().head
}
}
当我尝试将其与userId = None
或email = None
一起使用时,它会与
org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $1
有没有办法将null参数推送到预准备语句?