[jOOQ/jOOQ#9926] Emulate SQL Server FOR JSON also in Db2
This requires emulating JSON_ARRAYAGG using '[' || LISTAGG(..) || ']' and some additional JSON FORMAT management
This commit is contained in:
parent
23499724bd
commit
705ad32b76
@ -37,6 +37,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
*/
|
||||
package org.jooq;
|
||||
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
|
||||
@ -44,6 +44,7 @@ package org.jooq;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
// ...
|
||||
|
||||
@ -67,6 +67,7 @@ import static org.jooq.SQLDialect.MYSQL;
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
// ...
|
||||
// ...
|
||||
|
||||
@ -47,6 +47,7 @@ import static org.jooq.impl.Names.N_JSON_AGG;
|
||||
import static org.jooq.impl.Names.N_JSON_ARRAYAGG;
|
||||
import static org.jooq.impl.Names.N_JSON_MERGE;
|
||||
import static org.jooq.impl.SQLDataType.JSON;
|
||||
import static org.jooq.impl.SQLDataType.VARCHAR;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -84,11 +85,7 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
case MYSQL: {
|
||||
// Workaround for https://jira.mariadb.org/browse/MDEV-21912,
|
||||
// https://jira.mariadb.org/browse/MDEV-21914, and other issues
|
||||
Field<?> concat = Tools.isEmpty(withinGroupOrderBy)
|
||||
? DSL.concat(inline('['), groupConcat(arguments.get(0)), inline(']'))
|
||||
: DSL.concat(inline('['), groupConcat(arguments.get(0)).orderBy(withinGroupOrderBy), inline(']'));
|
||||
|
||||
ctx.visit(N_JSON_MERGE).sql('(').visit(inline("[]")).sql(", ").visit(concat).sql(')');
|
||||
ctx.visit(N_JSON_MERGE).sql('(').visit(inline("[]")).sql(", ").visit(groupConcatEmulation()).sql(')');
|
||||
break;
|
||||
}
|
||||
|
||||
@ -97,6 +94,13 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case POSTGRES:
|
||||
ctx.visit(getDataType() == JSON ? N_JSON_AGG : N_JSONB_AGG).sql('(');
|
||||
ctx.visit(arguments.get(0));
|
||||
@ -115,6 +119,12 @@ implements JSONArrayAggOrderByStep<J> {
|
||||
}
|
||||
}
|
||||
|
||||
private final Field<?> groupConcatEmulation() {
|
||||
return Tools.isEmpty(withinGroupOrderBy)
|
||||
? DSL.concat(inline('['), groupConcat(arguments.get(0)), inline(']'))
|
||||
: DSL.concat(inline('['), groupConcat(arguments.get(0)).orderBy(withinGroupOrderBy), inline(']'));
|
||||
}
|
||||
|
||||
private final void acceptStandard(Context<?> ctx) {
|
||||
ctx.visit(N_JSON_ARRAYAGG).sql('(');
|
||||
ctx.visit(arguments.get(0));
|
||||
|
||||
@ -37,11 +37,14 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.impl.Keywords.K_FORMAT;
|
||||
import static org.jooq.impl.Keywords.K_JSON;
|
||||
import static org.jooq.impl.Keywords.K_KEY;
|
||||
import static org.jooq.impl.Keywords.K_VALUE;
|
||||
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.JSON;
|
||||
import org.jooq.JSONEntry;
|
||||
|
||||
|
||||
@ -82,6 +85,15 @@ final class JSONEntryImpl<T> extends AbstractQueryPart implements JSONEntry<T> {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
case POSTGRES:
|
||||
|
||||
@ -64,6 +64,7 @@ import static org.jooq.Operator.OR;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
// ...
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
@ -98,6 +99,7 @@ import static org.jooq.impl.CombineOperator.UNION_ALL;
|
||||
import static org.jooq.impl.DSL.asterisk;
|
||||
import static org.jooq.impl.DSL.falseCondition;
|
||||
import static org.jooq.impl.DSL.inline;
|
||||
import static org.jooq.impl.DSL.jsonArrayAgg;
|
||||
import static org.jooq.impl.DSL.name;
|
||||
import static org.jooq.impl.DSL.one;
|
||||
import static org.jooq.impl.DSL.orderBy;
|
||||
@ -166,6 +168,7 @@ import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.GroupField;
|
||||
import org.jooq.JSON;
|
||||
import org.jooq.JSONArrayAggOrderByStep;
|
||||
import org.jooq.JSONEntry;
|
||||
import org.jooq.JSONObjectNullStep;
|
||||
import org.jooq.JoinType;
|
||||
@ -571,6 +574,7 @@ final class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> imp
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user