简体   繁体   中英

SQL `NULL` read at column 1 (JDBC type null) but mapping is to a non-Option type

I want select the max value using this query (all fields in table are not null):

dc.run(quote {
    query[SchemaInfo]
      .filter(_.subjectName == lift(subject))
      .map(_.version)
      .max
  }).map(_.map(_ + 1).getOrElse(1))

I know, that table may be empty, so i use this: map(_.map(_ + 1).getOrElse(1)) .

The problem is that this query produces this error:

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: 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.

How to fix it? Without quill (using pure doobie) the same query working correctly

I know that you probably got the answer already, but I will leave my comment here so that it hopefully help someone in the future.

so the problem is in line query[SchemaInfo] as the record may not exist it should be mapped into query[Option[SchemaInfo]].unique

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM