【发布时间】:2021-07-21 07:50:53
【问题描述】:
我在表 MY_TABLE 上有一个部分索引,其定义如下:
CREATE UNIQUE INDEX my_index
ON MY_TABLE(CUSTOMER_ID, OWNER_ID)
WHERE CLOSED_ON IS NULL;
然后,我正在尝试使用 jOOQ 进行更新插入
final var insert = using(configuration)
.insertInto(MY_TABLE,
MY_TABLE.CUSTOMER_ID,
MY_TABLE.OWNER_ID,
MY_TABLE.UPDATED_ON);
customers.forEach(custId -> insert.values(custId, reprId, today));
insert.onConflict(MY_TABLE.CUSTOMER_ID, MY_TABLE.OWNER_ID)
.where(MY_TABLE.CLOSED_ON.isNull())
.doUpdate()
.set(MY_TABLE.UPDATED_ON, today)
.execute();
但是上面的代码抛出了这个错误:
org.jooq.exception.DataAccessException: SQL [...];
ERROR: invalid reference to FROM-clause entry for table "my_table"
Hint: There is an entry for table "my_table", but it cannot be referenced from this part of the query.
查看生成的 SQL,我看到 jOOQ 正在将架构和表名添加到 on conflict 的 where 部分,这是 Postgres 不喜欢的:
... on conflict ("customer_id", "owner_id") where "my_schema"."my_table"."closed_on" is null do update set ...
有没有办法告诉 jOOQ 不要添加模式和表名?
这是我正在使用的解决方法,但我想知道是否有更好的方法:
.where(condition("closed_on IS NULL"))
【问题讨论】:
标签: postgresql jooq