[jOOQ/jOOQ#9927] Fix PostgreSQL ABSENT ON NULL emulation
This commit is contained in:
parent
0844eb0c9b
commit
e977654051
@ -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();
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user