SQL-插值中的 ResultSetExtractorException

ResultSetExtractorException in SQL-Interpolation

我在 ScalikeJdbc 中遇到 SQL-Interpolation 的一些问题。尝试 运行 以下代码

val dbTableSQLSyntax: SQLSyntax = SQLSyntax.createUnsafely(dbTableName)

sql"""
   SELECT
     COUNT(*) AS count,
     MIN($distributionColumn) AS min,
     MAX($distributionColumn) AS max
   FROM
     $dbTableSQLSyntax
 """.stripMargin.
  map(mapResult).
  single().
  apply().
  get()

我收到这个错误

scalikejdbc.ResultSetExtractorException: Failed to retrieve value because For input string: "tab_id". If you're using SQLInterpolation, you may mistake u.id for u.resultName.id.
    at scalikejdbc.WrappedResultSet.wrapIfError(WrappedResultSet.scala:27)
    at scalikejdbc.WrappedResultSet.get(WrappedResultSet.scala:479)
    at scalikejdbc.WrappedResultSet.longOpt(WrappedResultSet.scala:233)
...


框架/库


EDIT-1

为了回应 @Kazuhiro Sera 的回答,我提供了我的 mapResult 方法

def mapResult(rs: WrappedResultSet): (Long, Long, Long) = {
  val count: Long = rs.long("count")
  val minOpt: Option[Long] = rs.longOpt("min")
  val maxOpt: Option[Long] = rs.longOpt("max")
  (count, minOpt.getOrElse(0), maxOpt.getOrElse(Long.MaxValue))
}

这取决于您的 mapResult 功能。恐怕 mapResult 会尝试从 ResultSet 值中获取 tag_id。在这种情况下,您的 SQL 查询 returns 仅 countminmax.