我想表达以下几点INSERT
陈述:
context.insertInto(TABLE A)
.set(<FIELD A, FIELD B>, context.select(FIELD A, FIELD B).from(B).where(...))
.set(... other field of table A ...)
.set(... other field of table A ...)
.set(... other field of table A ...)
.returning()
.fetch()
子选择返回一行两列(FIELD A
and FIELD B
) 需要插入到目标中TABLE A
。这样做的原因是<FIELD A, FIELD B>
是主键TABLE B
. TABLE A
指的是TABLE B
(外键)。
这可能吗?
我不确定这是否可以通过任何 SQL 方言首先实现INSERT .. VALUES
,但是你当然可以使用来表达这种查询INSERT .. SELECT
:
INSERT INTO a (a, b, x, y, z)
SELECT a, b, ... other value ..., ... other value ..., ... other value ...
FROM b
WHERE ...
RETURNING *;
或者使用 jOOQ
context.insertInto(TABLE A, ... columns ...)
.select(
select(
FIELD A,
FIELD B,
... other field of table A ...,
... other field of table A ...,
... other field of table A ...)
.from(B)
.where(...))
)
.returning()
.fetch()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)