我想表达以下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
和FIELD B
)的一行,需要将其插入到目标TABLE A
中.原因是<FIELD A, FIELD B>
是 TABLE B
的主键. TABLE A
指的是 TABLE B
(外键)。
这可能吗?
最佳答案
我不确定首先是否可以通过 INSERT .. VALUES
使用任何 SQL 方言,但是您当然可以使用 INSERT ..选择
:
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()
关于java - jOOQ - 用于插入的多字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959180/