lucidsoftware / relate

Performant database access in Scala
http://lucidsoftware.github.io/relate/
Apache License 2.0
161 stars 15 forks source link

Postgres: can't interpolate UUID fields #47

Open gregghz opened 7 years ago

gregghz commented 7 years ago

Relate assumes the database stores a UUID as a byte array. For (at least) postgres that isn't true since it has a concrete UUID column type.

this query

val u = java.util.UUID.fromString("9b14d7ae-702f-4ee7-9bd7-deda478b469e")

sql"SELECT * FROM tt where uuid = $u".asList(parser)

produces this error

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[PSQLException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 29]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
    at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
    at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
    at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
    at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 29
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:304)
    at com.lucidchart.relate.NormalStatementPreparer$class.results(StatementPreparer.scala:90)
    at com.lucidchart.relate.Sql$$anon$1.results(SqlQuery.scala:39)
    at com.lucidchart.relate.StatementPreparer$class.execute(StatementPreparer.scala:20)
    at com.lucidchart.relate.Sql$$anon$1.execute(SqlQuery.scala:39)