我想使用这个查询选择最大值(表中的所有字段都不为空):
dc.run(quote {
query[SchemaInfo]
.filter(_.subjectName == lift(subject))
.map(_.version)
.max
}).map(_.map(_ + 1).getOrElse(1))
我知道,那个表可能是空的,所以我使用这个:map(_.map(_ + 1).getOrElse(1))
。
问题是这个查询产生了这个错误:
SQL
NULL
read at column 1 (JDBC type null) but mapping is to a non-Option type; use Option here. Note that JDBC column indexing is 1-based. doobie.util.invariant$NonNullableColumnRead: SQLNULL
read at column 1 (JDBC type null) but mapping is to a non-Option type; use Option here. Note that JDBC column indexing is 1-based.
如何解决? 没有 quill(使用纯 doobie)相同的查询正常工作
最佳答案
我知道你可能已经得到了答案,但我会在这里留下我的评论,希望它能帮助将来的人。
所以问题是一致的
查询[SchemaInfo]
因为记录可能不存在,所以应该映射到
query[Option[SchemaInfo]].unique
关于scala - SQL `NULL` 在第 1 列读取(JDBC 类型为空)但映射到非选项类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57873699/