Skip to content

Commit

Permalink
[#8933] DSL.unnest(Collection) doesn't work on PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Jul 11, 2019
1 parent 4a166cb commit d941f44
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java
Expand Up @@ -965,7 +965,12 @@ final void sqlInline0(BindingSQLContext<U> ctx, Object[] value) throws SQLExcept
}

else if ( ctx.family() == POSTGRES) {
ctx.render().visit(cast(inline(PostgresUtils.toPGArrayString(value)), type));
Class<?> arrayType =
type == Object[].class
? componentType(value)
: type;

ctx.render().visit(cast(inline(PostgresUtils.toPGArrayString(value)), arrayType));
}

// By default, render HSQLDB syntax
Expand All @@ -987,6 +992,16 @@ else if ( ctx.family(
}
}

private final Class<?> componentType(Object[] value) {
for (Object o : value)
if (o != null)
return java.lang.reflect.Array.newInstance(o.getClass(), 0).getClass();

// PostgreSQL often defaults to using varchar as well, so we can
// mimick this behaviour (without documenting it).
return String[].class;
}

@Override
final void sqlBind0(BindingSQLContext<U> ctx, Object[] value) throws SQLException {
super.sqlBind0(ctx, value);
Expand Down

0 comments on commit d941f44

Please sign in to comment.