Search code examples
jooq

Is there a way to generate a query string with both inlined and indexed parameters?


On the org.jooq.Query.getSQL(ParamType paramType)method

Like ParamType.NAMED_OR_INLINED, but printing ? instead of the named parameter.

For example:

DSL.select(M3_PUSH.asterisk())
            .from(M3_PUSH)
            .where(M3_PUSH.PLATFORM.eq(param(String.class)).and(M3_PUSH.ALERTKEY.eq("TEST")))
            .getSQL()

Generates:

select "m3_push".* from "m3_push" where ("m3_push"."platform" = ? and "m3_push"."alertKey" = ?)

Whereas I'd like to have the second bindable parameter to be fixed:

select "m3_push".* from "m3_push" where ("m3_push"."platform" = ? and "m3_push"."alertKey" = "TEST")

Solution

  • Indexed or inlined parameters can be controlled on several levels. The first two don't work for you because they act globally:

    See also: https://www.jooq.org/doc/latest/manual/sql-building/bind-values/inlined-parameters