Piotrowy
Piotrowy

Reputation: 605

How to use plain SQL as derived table in JOOQ?

I think the title is quite self-explanatory. How can I use fetched plain sql as derived table in nested selects?

For example I want to fetch

select a.a, a.b from (select c.a, c.b from c) as a

and the

(select c.a, c.b from c)

part is a complicated postgres query which is not supported by JOOQ.

How can I make something like this:

nested = create.fetch("select c.a, c.b from c")

create.select(...)
    .from(nested)
    .fetch

Upvotes: 2

Views: 414

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220762

Use DSL.table(String)

Table<?> nested = DSL.table("(select c.a, c.b from c)").as("a")

create.select(...)
      .from(nested)
      .fetch();

Upvotes: 2

Related Questions