You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exception in thread "main" java.lang.ClassCastException: class [Ljava.sql.Timestamp; cannot be cast to class [Ljava.time.LocalDateTime; ([Ljava.sql.Timestamp; is in module java.sql of loader 'platform'; [Ljava.time.LocalDateTime; is in module java.base of loader 'bootstrap')
at com.foo.SleepTrackerAdapter.decode(Main.kt:21)
at com.foo.SleepTrackerQueries$getAllTracker$1.invoke(SleepTrackerQueries.kt:25)
at com.foo.SleepTrackerQueries$getAllTracker$1.invoke(SleepTrackerQueries.kt:19)
at app.cash.sqldelight.ExecutableQuery$executeAsList$1.invoke(Query.kt:176)
at app.cash.sqldelight.ExecutableQuery$executeAsList$1.invoke(Query.kt:174)
at app.cash.sqldelight.driver.jdbc.JdbcPreparedStatement.executeQuery(JdbcDriver.kt:283)
at app.cash.sqldelight.driver.jdbc.JdbcDriver.executeQuery(JdbcDriver.kt:155)
at app.cash.sqldelight.SimpleQuery.execute(Query.kt:98)
at app.cash.sqldelight.ExecutableQuery.executeAsList(Query.kt:174)
at com.foo.MainKt.main(Main.kt:18)
at com.foo.MainKt.main(Main.kt)
wreedamz
changed the title
cannot query column with type TIMESTAMP[] AS List<Instant>
postgres: cannot query column with type TIMESTAMP[] AS List<Instant>
Dec 18, 2024
Sadly, I think this is an issue with PostgreSql JDBC see pgjdbc/pgjdbc#1225
Currently the JDBC driver has no support for Array<Timestamp> to Array<LocalDateTime> - it does for single column types Timestamp to LocalDateTime
Possible work-around - use a manual mapper to unpack the Array
(note the SleepTrackerAdapter adapter is not used except to generate the Instant field on the data table)
e.g
val mapper: (SqlCursor) ->SleepTracker= { cursor ->
check(cursor isJdbcCursor)
val patientId:Int= cursor.getInt(0)!!val times = cursor.getArray<Timestamp>(1)!!SleepTracker(patientId, times.map { it.toInstant() })
}
val qry =object:ExecutableQuery<SleepTracker>(mapper) {
overridefun <R> execute(mapper: (SqlCursor) ->QueryResult<R>): QueryResult<R> {
return driver.executeQuery(-1, "SELECT * FROM sleepTracker", mapper, 0) {}
}
}
println(qry.executeAsList())
SQLDelight Version
2.0.2
Application Operating System
postgresql, macos
Describe the Bug
I have a table
and an adapter
When I query the database via sqldelight with
I get
Repository reproducing issue
The text was updated successfully, but these errors were encountered: