[#10089] Emulate JSON_OBJECTAGG in CockroachDB

This commit is contained in:
Lukas Eder 2020-04-21 11:54:46 +02:00
parent a444521fba
commit e1d6fdeb00
2 changed files with 17 additions and 1 deletions

View File

@ -53,6 +53,7 @@ import static org.jooq.impl.SQLDataType.JSON;
import org.jooq.Context;
import org.jooq.DataType;
import org.jooq.Field;
import org.jooq.JSON;
import org.jooq.JSONEntry;
import org.jooq.JSONObjectAggNullStep;
@ -132,7 +133,19 @@ implements JSONObjectAggNullStep<J> {
value = entry.value();
}
else {
value = jsonValue(jsonObject(inline("x"), entry.value()), inline("$.x"));
Field<JSON> x = jsonObject(inline("x"), entry.value());
switch (ctx.family()) {
default:
value = jsonValue(x, inline("$.x"));
break;
}
if (nullClause == ABSENT_ON_NULL)
value = when(entry.value().isNull(), inline((String) null)).else_((Field) value);

View File

@ -182,6 +182,9 @@ implements
ctx.visit(N_JSON_EXTRACT).sql('(').visit(json).sql(", ").visit(path).sql(')');
break;
case POSTGRES:
ctx.visit(N_JSONB_PATH_QUERY_FIRST).sql('(').visit(castIfNeeded(json, JSONB)).sql(", ").visit(path).sql("::jsonpath)");
break;