fedor.belov
fedor.belov

Reputation: 23343

jooq: How to configure dialect for static DSL methods?

I've got dsl with POSTGRES_9_4 dialect. I try to use custom selection query with org.jooq.impl.DSL.Condition:

dsl.selectFrom(TAG_JSON).where(condition("translations ??| array[?]", normValues)).fetch(mapper);

It throws an exception:

org.jooq.exception.SQLDialectNotSupportedException: Type class java.util.ArrayList is not supported in dialect DEFAULT
    at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:757)
    at org.jooq.impl.DefaultDataType.getDataType(DefaultDataType.java:704)
    at org.jooq.impl.DSL.getDataType(DSL.java:14371)
    at org.jooq.impl.Utils.queryParts(Utils.java:1565)
    at org.jooq.impl.SQLImpl.<init>(SQLImpl.java:64)
    at org.jooq.impl.DSL.sql(DSL.java:6240)
    at org.jooq.impl.DSL.condition(DSL.java:7323)

Why DEFAULT dialect is used? How to configure global one?

Upvotes: 1

Views: 2546

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221145

The error message is a bit misleading. Your intention seems for array[?] to take a List<String> as a single bind value to pass to an array constructor. This won't work. You have two options:

Binding a single array

condition("translations <op> ?::text[]", normValues.toArray(new String[0]))

Binding the array as a list of bind values

condition("translations <op> {0}", list(
    normValues.stream().map(DSL::val).toArray(QueryPart[]::new)
))

This is using DSL.list() to create a list of bind variables.

Note, in both cases, I have avoided your ??| operator because jOOQ parses plain SQL text for bind values (?) and currently doesn't recognise ??| as a non-bind variable sequence (I've registered an issue for this). If that operator has a textual alternative representation, I recommend using that instead.

Upvotes: 1

Related Questions