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

1.5k Views Asked by At

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

1

There are 1 best solutions below

1
On BEST ANSWER

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