[英]inline with name in returning section ignores value in Jooq
在Jooq 3.10的返回部分中似乎无法用名称内联值
我试过这样的查询
val role = name("role").fields("role_id")
.`as`(select(ROLES.ROLE_ID)
.from(ROLES)
.where(ROLES.LEGACY_ID.eq(roleId)))
return dsl.with(role)
.insertInto(USER)
.columns(
USER.EMAIL,
USER.ROLE_ID)
.select(
select(
inline(email),
role.field("role_id", Int::class.java))
.from(role))
.onConflict(USER.EMAIL)
.doNothing()
.returning(USER.EMAIL, inline(roleId).as("role))
和
val role = name("role").fields("role_id")
.`as`(select(ROLES.ROLE_ID)
.from(ROLES)
.where(ROLES.LEGACY_ID.eq(roleId)))
return dsl.with(role)
.insertInto(USER)
.columns(
USER.EMAIL,
USER.ROLE_ID)
.select(
select(
inline(email),
role.field("role_id", Int::class.java))
.from(role))
.onConflict(USER.EMAIL)
.doNothing()
.returning(USER.EMAIL, inline(roleId))
在第一种情况下,它被转换成这样的sql
select
'new_email@expedia.com',
role.role_id
from role
on conflict (email) do nothing
returning
auction.user.email,
role
我收到一个错误消息,没有角色字段
在第二种情况下,它被转换为
select
'new_email@expedia.com',
role.role_id
from role
on conflict (email) do nothing
returning
auction.user.email,
2
而且在获取阶段无法按名称引用内联列
确实, InsertReturningStep.returning()
方法存在一个已知且非常不幸的局限性,只允许从您插入的表中投影列,而不能使用表达式。
在jOOQ 3.11中,通过问题#1234通过新的InsertReturningStep.returningResult()
方法解决了该问题。 由于向后兼容的限制,未对原始方法进行改进。 您现在可以执行以下操作:
.returningResult(USER.EMAIL, inline(roleId))
我认为jOOQ 3.11中没有解决此问题的简便方法,只是将整个查询转换为简单的SQL模板查询
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.