[jOOQ/jOOQ#9927] Fix PostgreSQL ABSENT ON NULL emulation

This commit is contained in:
Lukas Eder 2020-03-11 10:51:23 +01:00
parent 0844eb0c9b
commit e977654051
4 changed files with 10 additions and 13 deletions

View File

@ -40,8 +40,6 @@ package org.jooq;
// ...
// ...
import static org.jooq.SQLDialect.H2;
import static org.jooq.SQLDialect.MARIADB;
import static org.jooq.SQLDialect.MYSQL;
// ...
import static org.jooq.SQLDialect.POSTGRES;
@ -59,12 +57,12 @@ public interface JSONArrayAggNullStep<T> extends AggregateFilterStep<T> {
/**
* Include <code>NULL</code> values in output JSON.
*/
@Support({ H2, MARIADB, MYSQL, POSTGRES })
@Support({ H2, POSTGRES })
AggregateFilterStep<T> nullOnNull();
/**
* Exclude <code>NULL</code> values in output JSON.
*/
@Support({ H2, MARIADB, MYSQL, POSTGRES })
@Support({ H2, POSTGRES })
AggregateFilterStep<T> absentOnNull();
}

View File

@ -40,8 +40,6 @@ package org.jooq;
// ...
// ...
import static org.jooq.SQLDialect.H2;
import static org.jooq.SQLDialect.MARIADB;
import static org.jooq.SQLDialect.MYSQL;
// ...
import static org.jooq.SQLDialect.POSTGRES;
@ -60,12 +58,12 @@ public interface JSONArrayAggOrderByStep<J> extends JSONArrayAggNullStep<J> {
/**
* Add an <code>ORDER BY</code> clause to the function.
*/
@Support({ H2, MARIADB, MYSQL, POSTGRES })
@Support({ H2, POSTGRES })
JSONArrayAggNullStep<J> orderBy(OrderField<?>... fields);
/**
* Add an <code>ORDER BY</code> clause to the function.
*/
@Support({ H2, MARIADB, MYSQL, POSTGRES })
@Support({ H2, POSTGRES })
JSONArrayAggNullStep<J> orderBy(Collection<? extends OrderField<?>> fields);
}

View File

@ -151,6 +151,10 @@ implements
}
final void acceptFilterClause(Context<?> ctx) {
acceptFilterClause(ctx, filter);
}
static final void acceptFilterClause(Context<?> ctx, Condition filter) {
if (filter != null && SUPPORT_FILTER.contains(ctx.dialect()))
ctx.sql(' ')
.visit(K_FILTER)

View File

@ -37,7 +37,6 @@
*/
package org.jooq.impl;
import static org.jooq.impl.DSL.unquotedName;
import static org.jooq.impl.JSONNullClause.ABSENT_ON_NULL;
import static org.jooq.impl.JSONNullClause.NULL_ON_NULL;
import static org.jooq.impl.JSONObject.acceptJSONNullClause;
@ -84,16 +83,14 @@ implements JSONArrayAggOrderByStep<J> {
case POSTGRES:
if (nullClause == ABSENT_ON_NULL)
ctx.visit(unquotedName("json_strip_nulls")).sql('(');
ctx.visit(getDataType() == JSON ? N_JSON_AGG : N_JSONB_AGG).sql('(');
ctx.visit(arguments.get(0));
acceptOrderBy(ctx);
ctx.sql(')');
// TODO: What about a user-defined filter clause?
if (nullClause == ABSENT_ON_NULL)
ctx.sql(')');
acceptFilterClause(ctx, arguments.get(0).isNotNull());
break;