[jOOQ/jOOQ#10788] DSL.jsonbArray() generates json_build_array() call in

PostgreSQL, instead of jsonb_build_array()
This commit is contained in:
Lukas Eder 2020-10-22 17:12:31 +02:00
parent 4b34e97651
commit 1079205958
2 changed files with 12 additions and 3 deletions

View File

@ -39,16 +39,19 @@ package org.jooq.impl;
import static org.jooq.SQLDialect.H2;
import static org.jooq.impl.DSL.jsonArrayAgg;
import static org.jooq.impl.DSL.jsonbArrayAgg;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.select;
import static org.jooq.impl.DSL.unquotedName;
import static org.jooq.impl.DSL.values;
import static org.jooq.impl.JSONEntryImpl.jsonCastMapper;
import static org.jooq.impl.JSONNull.JSONNullType.ABSENT_ON_NULL;
import static org.jooq.impl.JSONNull.JSONNullType.NULL_ON_NULL;
import static org.jooq.impl.Keywords.K_JSON_ARRAY;
import static org.jooq.impl.Names.N_JSONB_BUILD_ARRAY;
import static org.jooq.impl.Names.N_JSON_ARRAY;
import static org.jooq.impl.Names.N_JSON_BUILD_ARRAY;
import static org.jooq.impl.QueryPartListView.wrap;
import static org.jooq.impl.SQLDataType.JSON;
import java.util.Collection;
@ -122,10 +125,14 @@ final class JSONArray<J> extends AbstractField<J> implements JSONArrayNullStep<J
Table<?> t = values(rows).as("t", "a");
Field<?> a = t.field("a");
ctx.visit(DSL.field(select(jsonArrayAgg(a)).from(t).where(a.isNotNull())));
ctx.visit(DSL.field(
select((Field<?>) (getDataType() == JSON ? jsonArrayAgg(a) : jsonbArrayAgg(a)))
.from(t)
.where(a.isNotNull())
));
}
else {
ctx.visit(unquotedName("json_build_array")).sql('(').visit(args).sql(')');
ctx.visit(getDataType() == JSON ? N_JSON_BUILD_ARRAY : N_JSONB_BUILD_ARRAY).sql('(').visit(args).sql(')');
}
break;

View File

@ -132,6 +132,7 @@ final class Names {
static final Name N_JSON_AGG = unquotedName("json_agg");
static final Name N_JSON_ARRAY = unquotedName("json_array");
static final Name N_JSON_ARRAYAGG = unquotedName("json_arrayagg");
static final Name N_JSON_BUILD_ARRAY = unquotedName("json_build_array");
static final Name N_JSON_CONTAINS_PATH = unquotedName("json_contains_path");
static final Name N_JSON_EXTRACT = unquotedName("json_extract");
static final Name N_JSON_MERGE = unquotedName("json_merge");
@ -142,6 +143,7 @@ final class Names {
static final Name N_JSON_TABLE = unquotedName("json_table");
static final Name N_JSON_VALUE = unquotedName("json_value");
static final Name N_JSONB_AGG = unquotedName("jsonb_agg");
static final Name N_JSONB_BUILD_ARRAY = unquotedName("jsonb_build_array");
static final Name N_JSONB_OBJECT = unquotedName("jsonb_object");
static final Name N_JSONB_OBJECT_AGG = unquotedName("jsonb_object_agg");
static final Name N_JSONB_OBJECTAGG = unquotedName("jsonb_objectagg");