如何解决“订单”处或附近的语法错误带有 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。解决方法是重命名表中的列(以及相应的案例类)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。