"order" 处或附近的语法错误(Scala with Quill、Doobie 和 PostgreSQL)

Syntax error at or near "order" (Scala with Quill, Doobie and PostgreSQL)

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

此代码

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

val record = SomeRecord(0, 0, "test")

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

将在运行时出现错误消息:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "order" Position: 46 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164) at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130) at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) at doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeUpdate(kleisliinterpreter.scala:955) at doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeUpdate$adapted(kleisliinterpreter.scala:955) at doobie.free.KleisliInterpreter.$anonfun$primitive(kleisliinterpreter.scala:109)

似乎 Quill 不会转义类似关键字的列名,因此查询中的“order”(和其他关键字)列总是会失败。请参阅 Escaping keyword-like column names in Postgres。解决方法是重命名 table 中的列(以及对应的大小写 类)。