【发布时间】:2019-08-21 16:17:38
【问题描述】:
我正在编写一个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!
【问题讨论】:
标签: postgresql jooq