I need to do the equivalent of this in JOOQ.
SELECT
name,
'companyType' AS resultType
FROM company
UNION ALL
SELECT
name,
'userType' AS resultType
FROM "user";
I have figured out how to do unionall in JOOQ fine but I cannot figure out how to select a constant value for results in either select of the union.
You're looking for DSL.inline()
, which is used for precisely this:
inline("companyType").as("resultType")
Or, the full query:
using(configuration)
.select(COMPANY.NAME, inline("companyType").as("resultType"))
.from(COMPANY)
.unionAll(
select(USER.NAME, inline("userType").as("resultType"))
.from(USER))
.fetch();
Both examples assume you have this static import:
import static org.jooq.impl.DSL.*;
More information can be found here: http://www.jooq.org/doc/latest/manual/sql-building/bind-values/inlined-parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With