1

I am trying to get jOOQ to emit this (without much luck):

SELECT array_agg(DISTINCT my_field) FROM ...

I ended up using a plain-SQL field.

Is there a way to do this that I am missing?

If not, would it make sense to add a .distinct() method to Field that can be used with any aggregate function? Or a DSL.distinct(Field) that creates a Field, rather than a SelectStep - not sure if that makes a difference.

This currently seems to be accomplished by creating separate DSL methods for each aggregate: countDistinct, groupConcatDistinct, min/max/sum/avgDistinct, etc.

Thanks

1 Answer 1

1

There will be a DSL.arrayAggDistinct() function available from jOOQ 3.10 onwards: https://github.com/jOOQ/jOOQ/issues/6281

Until then, simply use the plain SQL API as a workaround:

public static <T> Field<T[]> arrayAggDistinct(Field<T> myField) {
    return DSL.field("array_agg(distinct {0})", myField.getArrayDataType(), myField);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.