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
If there's a 'timestamp' field and the 'where' clause generates to where ? is null, it will fail with error: could not determine data type of parameter $1
package example
import io.getquill.*
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import java.sql.Timestamp
import javax.sql.DataSource
import org.postgresql.ds.PGSimpleDataSource
import org.scalatest.Ignore
class QuillTimestampBugTest extends AnyFlatSpec with Matchers:
private val pgDataSource = new PGSimpleDataSource()
pgDataSource.setURL("jdbc:postgresql://localhost:5400/testdb")
pgDataSource.setUser("postgres")
pgDataSource.setPassword("postgres")
val ctx = new PostgresJdbcContext(SnakeCase, pgDataSource)
import ctx._
"queryWithNullTimestamp" should "generate correct SQL for None timestamp" in {
val ts: Option[Timestamp] = None
val q = queryWithNullTimestamp(ts)
val sql = ctx.translate(q)
sql should include("WHERE null IS NULL")
println(s"Generated SQL: $sql")
}
it should "run the query without throwing an exception" in {
val ts: Option[Timestamp] = None
val q = queryWithNullTimestamp(ts)
noException should be thrownBy ctx.run(q)
}
private def queryWithNullTimestamp(ts: Option[Timestamp]) =
quote {
query[MyTable].filter(t => lift(ts).isEmpty)
}
Workaround
The query needs to change where ? is null to where ?::timestamp is null to get around the PostgreSQL limitation.
@getquill/maintainers
The text was updated successfully, but these errors were encountered:
Version: (e.g.
4.8.4
)Module: (e.g.
quill-jdbc
)Database: (e.g.
postgres
)Expected behaviour
This is a PostgreSQL bug/limitation but will appear in certain conditions when using quill to generate queries.
Someone raised it with PostgreSQL a long time ago but nothing that I'm aware of has been fixed:
https://www.postgresql.org/message-id/CAG2M1febgZbhBwm0DQK4Y5ekDrTbzTyAa1syKcdXw%2B6Y8caK4g%40mail.gmail.com
Actual behaviour
If there's a 'timestamp' field and the 'where' clause generates to
where ? is null
, it will fail with error:could not determine data type of parameter $1
Steps to reproduce the behaviour
docker-compose.yml:
init.sql:
build.sbt:
QuillTimestampBugTest.scala:
Workaround
The query needs to change
where ? is null
towhere ?::timestamp is null
to get around the PostgreSQL limitation.@getquill/maintainers
The text was updated successfully, but these errors were encountered: