我正在以INSERT INTO ... RETURNING的形式编写一个SQL查询,然后想要聚合结果。对于postgres,这是可能的:
DROP TABLE IF EXISTS __test;
CREATE TEMPORARY TABLE __test
(
id int not null,
value text not null
);
WITH things AS (
INSERT INTO __test
VALUES (1, 'foo'),
(2, 'bar'),
(2, 'baz')
RETURNING *
)
SELECT id,
array_agg(value)
FROM things
GROUP BY id;
尽管我正在努力寻找一种用jooq做到这一点的方法,因为InsertResultStep
并没有实现Select
,也没有实现Table
或TableLike
接口。有没有一种规范的方法可以实现这一目标,或者我应该寻找解决方法?
val insertQuery = DSL
.insertInto(otherTable)
.select(
DSL.select(recordPkColumns)
.from(recordTable)
.crossJoin(permValues)
.where(filter(command.command))
)
.onConflictDoNothing()
.returning()
DSL.select()
.from(insertQuery) // problem is here!
答案 0 :(得分:1)
从jOOQ 3.11(以及不久的3.12)开始,如果不依靠plain SQL templating,这在jOOQ中是不可能的。
相关功能请求在这里:https://github.com/jOOQ/jOOQ/issues/4474