“订单”处或附近的语法错误带有 Quill、Doobie 和 PostgreSQL 的 Scala

问题描述

我将 Quill 与 Doobie 和 PostgreSQL(org.tpolecat.doobie-quill 版本 0.13.1 的工件)一起使用。

此代码

case class SomeRecord(id: Int,order: Int,name: String)

val record = SomeRecord(0,"test")

run(
  quote(
    querySchema[SomeRecord]("some_table")
  ).insert(lift(record))
)

最终会在运行时出现错误消息:

org.postgresql.util.PSQLException:错误:“订单”处或附近的语法错误 职位:46 在 org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) 在 org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) 在 org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) 在 org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481) 在 org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401) 在 org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164) 在 org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130) 在 com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) 在 com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) 在 doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeUpdate$5(kleisliinterpreter.scala:955) 在 doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeUpdate$5$adapted(kleisliinterpreter.scala:955) 在 doobie.free.KleisliInterpreter.$anonfun$primitive$2(kleisliinterpreter.scala:109)

解决方法

似乎 Quill 不会对类似关键字的列名进行转义,因此其查询中的“order”(和其他关键字)列将始终失败。见Escaping keyword-like column names in Postgres。解决方法是重命名表中的列(以及相应的案例类)。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...