[jOOQ/jOOQ#14416] Support UNNEST(ARRAY[...]) in dialects that do not otherwise support arrays

This commit is contained in:
Lukas Eder 2022-12-16 16:26:21 +01:00
parent 80395e3c5b
commit e8175b9392
2 changed files with 17 additions and 4 deletions

View File

@ -67,7 +67,7 @@ final class Array<T> extends AbstractField<T[]> implements QOM.Array<T> {
private static final Set<SQLDialect> REQUIRES_CAST = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB);
private final FieldsImpl<Record> fields;
final FieldsImpl<Record> fields;
Array(Collection<? extends Field<T>> fields) {
super(N_ARRAY, type(fields));

View File

@ -177,6 +177,8 @@ implements
}
private final QueryPart table(Configuration configuration) {
boolean isArray = array.getDataType().getType().isArray();
switch (configuration.family()) {
@ -187,6 +189,8 @@ implements
// Most dialects can simulate unnested arrays using UNION ALL
@ -211,8 +215,12 @@ implements
case MARIADB:
case MYSQL:
case SQLITE:
if (array.getDataType().getType().isArray() && array instanceof Param)
return emulate();
if (isArray && array instanceof Param)
return emulateParam();
// [#14416] While Array isn't supported everywhere, Unnest(Array) is
else if (isArray && array instanceof Array)
return emulateArray();
@ -283,7 +291,12 @@ implements
}
@SuppressWarnings("unchecked")
private final QueryPart emulate() {
private final QueryPart emulateParam() {
return new ArrayTableEmulation(((Param<Object[]>) array).getValue(), fieldAliases);
}
@SuppressWarnings("unchecked")
private final QueryPart emulateArray() {
return new ArrayTableEmulation(((Array<Object>) array).fields.fields, fieldAliases);
}
}