@SuppressWarnings("unchecked") @Override final Field<T> getFunction0(Configuration configuration) { // In any dialect, a single argument is always the least if (getArguments().length == 1) { return (Field<T>) getArguments()[0]; } switch (configuration.family()) { // This implementation has O(2^n) complexity. Better implementations // are very welcome case DERBY: { Field<T> first = (Field<T>) getArguments()[0]; Field<T> other = (Field<T>) getArguments()[1]; if (getArguments().length > 2) { Field<?>[] remaining = new Field<?>[getArguments().length - 2]; System.arraycopy(getArguments(), 2, remaining, 0, remaining.length); return DSL.when(first.lessThan(other), DSL.least(first, remaining)) .otherwise(DSL.least(other, remaining)); } else { return DSL.when(first.lessThan(other), first).otherwise(other); } } case FIREBIRD: return function("minvalue", getDataType(), getArguments()); case SQLITE: return function("min", getDataType(), getArguments()); default: return function("least", getDataType(), getArguments()); } }