I'm facing some issues with SQL-Interpolation in ScalikeJdbc
. Upon trying to run following piece of code
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()
I get this error
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)
...
Frameworks / Libraries
Scala 2.11.11
"org.scalikejdbc" %% "scalikejdbc" % "3.2.0"
EDIT-1
In response to @Kazuhiro Sera's answer, I'm providing my mapResult
method
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))
}
It depends on your mapResult
function. I am afraid that mapResult
tries to fetch tag_id
from the ResultSet value. In this case, your SQL query returns only count
, min
, and max
.