【发布时间】:2018-03-25 13:57:45
【问题描述】:
我有一个包含发布信息的数据库表。一个版本有一个次要版本号,它是一个整数。我想执行一个查询,从给定版本中读取值并返回表中所有字段的当前值(减去 ID),并且次要版本增加一。
下面的查询返回当前值,但我不知道如何将当前值加一。
select(Arrays
.stream(V_RELEASE.fields())
.filter(f -> !f.equals(V_RELEASE.ID))
.map(f -> f.equals(V_RELEASE.MINOR_VERSION)
? V_RELEASE.MINOR_VERSION <-- I want to increase this by 1
: V_RELEASE.field(f))
.collect(Collectors.toList()))
.from(V_RELEASE)
.where(V_RELEASE.ID.eq(id))
我确信这有一个非常简单的解决方案,但我已经把头撞在墙上几个小时了,但无济于事。任何人都可以用正确的语法帮助 jOOQ 新手吗?
添加上下文:
我的查询基于对以下问题的答复:
JOOQ fetch record from table and insert it into another table
完整的查询应该是在现有记录的基础上创建一条新记录,次要版本增加 1,如下所示:
ctx
.insertInto(V_RELEASE)
.columns(Arrays.stream(V_RELEASE.fields())
.filter(f -> !f.equals(V_RELEASE.ID))
.collect(Collectors.toList()))
.select(
select(Arrays
.stream(V_RELEASE.fields())
.filter(f -> !f.equals(V_RELEASE.ID))
.map(f -> f.equals(V_RELEASE.MINOR_VERSION)
// I want to increase the minor version number by 1
? V_RELEASE.MINOR_VERSION
: V_RELEASE.field(f))
.collect(Collectors.toList()))
.from(V_RELEASE)
.where(V_RELEASE.ID.eq(id))
)
.execute();
【问题讨论】: