Slick 3.1.1 sql PSQLException: ERROR: syntax error at or near "" + ""
Slick 3.1.1 sql PSQLException: ERROR: syntax error at or near "" + ""
我有以下导致上述错误的简单(并在 Postgres 中测试)查询,但我找不到它是什么。
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: 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$$anonfun$apply.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$$anonfun$apply.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith.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)
您的字符串有误 - 以下是 Scala 中多行字符串的处理方式:https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch01s03.html
换句话说,它应该是这样的:
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)
}
我有以下导致上述错误的简单(并在 Postgres 中测试)查询,但我找不到它是什么。
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: 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$$anonfun$apply.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$$anonfun$apply.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith.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)
您的字符串有误 - 以下是 Scala 中多行字符串的处理方式:https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch01s03.html
换句话说,它应该是这样的:
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)
}