1
我有以下簡單(並在Postgres中測試)查詢導致上述錯誤,我無法找到它是什麼。油滑3.1.1 sql PSQLException:錯誤:在「」+「或」「附近的語法錯誤」
def findActiveByProviderKeyAndEmail(providerKey: String, email: String): Future[Option[UserRow]] = {
val action = sql"""SELECT t1.* FROM user t1 " +
"WHERE t1.active=true AND " +
" t1.email=$email AND " +
" EXISTS (SELECT * FROM linked_account t2 " +
" WHERE t2.user_id=t1.id AND " +
" t2.provider_key=$providerKey)""".as[UserRow].headOption
db.run(action)
}
請注意,我用的是${User.baseTableRow.tableName}
代替user
和${LinkedAccount.baseTableRow.tableName}
代替linked_account
但在此之前刪除了排除故障的可能性。
完整的運行時錯誤是:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[PSQLException: ERROR: syntax error at or near "" +
""
Position: 26]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:100)
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)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "" +
""
Position: 26
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:157)
at com.zaxxer.hikari.proxy.PreparedStatementProxy.execute(PreparedStatementProxy.java:44)
at com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy.execute(PreparedStatementJavassistProxy.java)
at slick.jdbc.StatementInvoker.results(StatementInvoker.scala:39)