jOOQ - 如何使用 .whereNotExists() 进行条件更新?

jOOQ - how to use .whereNotExists() with conditional update?

我有以下 jOOQ 查询,最初是在 Lukas Eder in 问题的帮助下编写的。

create.insertInto(DATA,DATA.TICKER,DATA.OPEN,DATA.HIGH,DATA.LOW,DATA.CLOSE,DATA.DATE)
.select(
    select(
        val(dailyData.getTicker()),
        val(dailyData.getOpen()),
        val(dailyData.getHigh()),
        val(dailyData.getLow()),
        val(dailyData.getClose()),
        val(dailyData.getDate())
        )
    .whereNotExists(
        selectOne()
        .from(DATA)
        .where(DATA.DATE.eq(dailyData.getDate()))
    )
).execute();

这个查询工作正常。另外,我想修改以完成以下壮举,但我不确定它是否真的可行。用简单的英语:

"Insert the row if a row with the same 'date' column doesn't already exist in the table. If it exists AND 'realtime close' column is true, update the 'close', otherwise do nothing."

第一部分已包含在现有查询中,但第二部分 if...update... 未涵盖,这正是我需要帮助的地方。

在普通 PostgreSQL 中,您可以按如下方式编写此查询:

INSERT INTO data (ticker, open, high, low, close, date)
VALUES (:ticker, :open, :high, :low, :close, :date)
ON CONFLICT (date)
DO UPDATE SET close = false WHERE close

这转换为以下 jOOQ 查询:

DSL.using(configuration)
   .insertInto(DATA)
   .columns(
       DATA.TICKER, 
       DATA.OPEN,
       DATA.HIGH,
       DATA.LOW,
       DATA.CLOSE,
       DATA.DATE)
   .values(
       dailyData.getTicker(),
       dailyData.getOpen(),
       dailyData.getHigh(),
       dailyData.getLow(),
       dailyData.getClose(),
       dailyData.getDate())
   .onConflict()
   .doUpdate()
   .set(DATA.CLOSE, inline(false))
   .where(DATA.CLOSE)
   .execute();