diff --git a/jOOQ/src/main/java/org/jooq/impl/RowSubqueryCondition.java b/jOOQ/src/main/java/org/jooq/impl/RowSubqueryCondition.java index df8e01d58e..33d4e2e852 100644 --- a/jOOQ/src/main/java/org/jooq/impl/RowSubqueryCondition.java +++ b/jOOQ/src/main/java/org/jooq/impl/RowSubqueryCondition.java @@ -61,6 +61,7 @@ import static org.jooq.impl.DSL.name; import static org.jooq.impl.DSL.notExists; import static org.jooq.impl.DSL.row; import static org.jooq.impl.DSL.select; +import static org.jooq.impl.Tools.embeddedFieldsRow; import static org.jooq.impl.Tools.visitSubquery; import java.util.Set; @@ -151,9 +152,10 @@ final class RowSubqueryCondition extends AbstractCondition { // [#2395] All other configurations have to be emulated else { String table = render == null ? "t" : render.nextAlias(); + Row l = embeddedFieldsRow(left); - String[] names = new String[left.size()]; - for (int i = 0; i < left.size(); i++) + String[] names = new String[l.size()]; + for (int i = 0; i < l.size(); i++) names[i] = table + "_" + i; Field[] fields = new Field[names.length]; @@ -166,7 +168,7 @@ final class RowSubqueryCondition extends AbstractCondition { case GREATER_OR_EQUAL: case LESS: case LESS_OR_EQUAL: - condition = new RowCondition(left, row(fields), comparator); + condition = new RowCondition(l, row(fields), comparator); break; case IN: @@ -174,7 +176,7 @@ final class RowSubqueryCondition extends AbstractCondition { case NOT_IN: case NOT_EQUALS: default: - condition = new RowCondition(left, row(fields), EQUALS); + condition = new RowCondition(l, row(fields), EQUALS); break; } diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index 3efe8541a9..bf982375ac 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -96,6 +96,7 @@ import static org.jooq.impl.DSL.getDataType; import static org.jooq.impl.DSL.keyword; import static org.jooq.impl.DSL.name; import static org.jooq.impl.DSL.nullSafeDataType; +import static org.jooq.impl.DSL.row; import static org.jooq.impl.DSL.select; import static org.jooq.impl.DSL.val; import static org.jooq.impl.DefaultExecuteContext.localConnection; @@ -5359,6 +5360,19 @@ final class Tools { : null; } + static final Row embeddedFieldsRow(Row row) { + if (hasEmbeddedFields(row.fields())) { + List> fields = new ArrayList<>(row.size()); + + for (Field f : flattenCollection(Arrays.asList(row.fields()), false)) + fields.add(f); + + return row(fields); + } + else + return row; + } + static final Field[] embeddedFields(ScalarSubquery field) { // Split a scalar subquery of degree N into N scalar subqueries of degree 1 @@ -5389,6 +5403,22 @@ final class Tools { } } + static final boolean hasEmbeddedFields(Field[] fields) { + for (Field f : fields) + if (f.getDataType().isEmbeddable()) + return true; + + return false; + } + + static final boolean hasEmbeddedFields(Iterable> fields) { + for (Field f : fields) + if (f.getDataType().isEmbeddable()) + return true; + + return false; + } + static final List collect(Iterable iterable) { if (iterable instanceof List) return (List) iterable;