gpt4 book ai didi

java - jOOQ - 用于插入的多字段

转载 作者:行者123 更新时间:2023-11-30 10:59:14 24 4
gpt4 key购买 nike

我想表达以下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 AFIELD 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com