java - Postgres : syntax error at or near "as"

标签 java sql postgresql syntax-error jooq

我正在使用 JOOQ for java 到 postgresql 数据库连接。它正在尝试运行此查询。

insert into "public"."mission_batches" as "MB" 
  ("micro_task_id", "is_active", "created_at", "updated_at") 
values 
  ('7e1cc9e8-fc11-409b-865e-3bf08e6ca924', false, timestamp '2016-10-05 21:47:13.061', timestamp '2016-10-05 21:47:13.061') returning "MB"."id", "MB"."micro_task_id", "MB"."is_active", "MB"."created_at", "MB"."updated_at"

但是我从数据库收到错误

org.jooq.exception.DataAccessException: SQL [insert into "public"."mission_batches" as "MB" ("micro_task_id", "is_active", "created_at", "updated_at") values (?, ?, cast(? as timestamp), cast(? as timestamp)) returning "MB"."id", "MB"."micro_task_id", "MB"."is_active", "MB"."created_at", "MB"."updated_at"];
ERROR: syntax error at or near "as"
  Position: 40

它正在与我的本地数据库[9.5]一起使用。在测试服务器 [9.4] 上,它抛出此错误。我应该去哪里寻找修复? Java端还是PG端?

最佳答案

为要插入的表设置别名仅在 Postgres 9.5 中添加(将 Postgres 9.5's documentation9.4's documentation 进行比较。由于 returning 子句中的列无论如何都引用插入的表,因此您可以没有它也同样容易:

insert into "public"."mission_batches"
  ("micro_task_id", "is_active", "created_at", "updated_at") 
values 
  ('7e1cc9e8-fc11-409b-865e-3bf08e6ca924', false,
   timestamp '2016-10-05 21:47:13.061', timestamp '2016-10-05 21:47:13.061') 
returning 
  "id", "micro_task_id", "is_active", "created_at", "updated_at"

关于java - Postgres : syntax error at or near "as",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39879172/

相关文章:

java - Android 内的 TabActivity 和导航

Java文件搜索问题

java - 提取 cassandra 的布隆过滤器

MySQL : Use Variable/Function Returned Value in Select

sql - 在 Postgresql 中的日期范围之间插入日期

java - 无法在android中使用Content-Disposition上传照片

MySQL (Wordpress) - 更新时的内部连接

sql - 查找字符串是否包含数字序列

perl - 如何在启用 utf-8 的情况下将 RapidApp 连接到 PostgreSQL

postgresql - 有多次通过 : How to select records with no relation OR by some condition in relation?