Hello Max,
Unfortunately, this is currently not possible as the CTE syntax requires an org.jooq.Select type, instead of an org.jooq.ResultQuery type. There's a pending feature request to improve this:
In particular, some databases like PostgreSQL also allow DML statements as CTE bodies:
WITH cte AS (
INSERT INTO table (a, b)
VALUES (1, 2)
RETURNING *
)
SELECT * FROM cte
So, there's a whole set of API changes that we'd like to implement to enable these features.
One workaround I can think of right now is for you to implement a reflection proxy that implements org.jooq.Select and delegates all calls to a backing plain SQL ResultQuery. It doesn't sound like a very robust workaround, though.
Another option is not to use a CTE, but a derived table, where plain SQL is perfectly possible.
Finally, if you externalise the CTE into a view, you can re-use the SQL string even more easily.
I hope this helps,
Lukas