Skip to content

Commit 60966f5

Browse files
committed
Fix inconsistencies and style issues in new SQL/JSON code
Reported by Alexander Lakhin. Discussion: https://postgr.es/m/60483139-5c34-851d-baee-6c0d014e1710@gmail.com
1 parent 589bb81 commit 60966f5

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/backend/executor/execExprInterp.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,10 +4479,7 @@ ExecEvalJsonConstructor(ExprState *state, ExprEvalStep *op,
44794479
jcstate->constructor->absent_on_null,
44804480
jcstate->constructor->unique);
44814481
else
4482-
{
4483-
res = (Datum) 0;
44844482
elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
4485-
}
44864483

44874484
*op->resvalue = res;
44884485
*op->resnull = isnull;

src/backend/parser/parse_expr.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,7 @@ makeJsonByteaToTextConversion(Node *expr, JsonFormat *format, int location)
31383138
}
31393139

31403140
/*
3141-
* Make CaseTestExpr node.
3141+
* Make a CaseTestExpr node.
31423142
*/
31433143
static Node *
31443144
makeCaseTestExpr(Node *expr)
@@ -3456,6 +3456,9 @@ coerceJsonFuncExpr(ParseState *pstate, Node *expr,
34563456
return res;
34573457
}
34583458

3459+
/*
3460+
* Make a JsonConstructorExpr node.
3461+
*/
34593462
static Node *
34603463
makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
34613464
List *args, Expr *fexpr, JsonReturning *returning,
@@ -3464,8 +3467,6 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
34643467
JsonConstructorExpr *jsctor = makeNode(JsonConstructorExpr);
34653468
Node *placeholder;
34663469
Node *coercion;
3467-
Oid intermediate_typid =
3468-
returning->format->format_type == JS_FORMAT_JSONB ? JSONBOID : JSONOID;
34693470

34703471
jsctor->args = args;
34713472
jsctor->func = fexpr;
@@ -3481,7 +3482,8 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
34813482
{
34823483
CaseTestExpr *cte = makeNode(CaseTestExpr);
34833484

3484-
cte->typeId = intermediate_typid;
3485+
cte->typeId = returning->format->format_type == JS_FORMAT_JSONB ?
3486+
JSONBOID : JSONOID;
34853487
cte->typeMod = -1;
34863488
cte->collation = InvalidOid;
34873489

@@ -3501,7 +3503,7 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
35013503
*
35023504
* JSON_OBJECT() is transformed into json[b]_build_object[_ext]() call
35033505
* depending on the output JSON format. The first two arguments of
3504-
* json[b]_build_object_ext() are absent_on_null and check_key_uniqueness.
3506+
* json[b]_build_object_ext() are absent_on_null and check_unique.
35053507
*
35063508
* Then function call result is coerced to the target type.
35073509
*/
@@ -3615,9 +3617,11 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
36153617
{
36163618
Oid aggfnoid;
36173619
Node *node;
3618-
Expr *aggfilter = agg_ctor->agg_filter ? (Expr *)
3619-
transformWhereClause(pstate, agg_ctor->agg_filter,
3620-
EXPR_KIND_FILTER, "FILTER") : NULL;
3620+
Expr *aggfilter;
3621+
3622+
aggfilter = agg_ctor->agg_filter ? (Expr *)
3623+
transformWhereClause(pstate, agg_ctor->agg_filter,
3624+
EXPR_KIND_FILTER, "FILTER") : NULL;
36213625

36223626
aggfnoid = DatumGetInt32(DirectFunctionCall1(regprocin,
36233627
CStringGetDatum(aggfn)));
@@ -3631,10 +3635,10 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
36313635
wfunc->wintype = aggtype;
36323636
/* wincollid and inputcollid will be set by parse_collate.c */
36333637
wfunc->args = args;
3638+
wfunc->aggfilter = aggfilter;
36343639
/* winref will be set by transformWindowFuncCall */
36353640
wfunc->winstar = false;
36363641
wfunc->winagg = true;
3637-
wfunc->aggfilter = aggfilter;
36383642
wfunc->location = agg_ctor->location;
36393643

36403644
/*
@@ -3659,16 +3663,19 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
36593663
aggref->aggtype = aggtype;
36603664

36613665
/* aggcollid and inputcollid will be set by parse_collate.c */
3662-
aggref->aggtranstype = InvalidOid; /* will be set by planner */
3666+
/* aggtranstype will be set by planner */
36633667
/* aggargtypes will be set by transformAggregateCall */
36643668
/* aggdirectargs and args will be set by transformAggregateCall */
36653669
/* aggorder and aggdistinct will be set by transformAggregateCall */
36663670
aggref->aggfilter = aggfilter;
36673671
aggref->aggstar = false;
36683672
aggref->aggvariadic = false;
36693673
aggref->aggkind = AGGKIND_NORMAL;
3674+
aggref->aggpresorted = false;
36703675
/* agglevelsup will be set by transformAggregateCall */
36713676
aggref->aggsplit = AGGSPLIT_SIMPLE; /* planner might change this */
3677+
aggref->aggno = -1; /* planner will set aggno and aggtransno */
3678+
aggref->aggtransno = -1;
36723679
aggref->location = agg_ctor->location;
36733680

36743681
transformAggregateCall(pstate, aggref, args, agg_ctor->agg_order, false);
@@ -3685,7 +3692,7 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
36853692
* Transform JSON_OBJECTAGG() aggregate function.
36863693
*
36873694
* JSON_OBJECTAGG() is transformed into
3688-
* json[b]_objectagg(key, value, absent_on_null, check_unique) call depending on
3695+
* json[b]_objectagg[_unique][_strict](key, value) call depending on
36893696
* the output JSON format. Then the function call result is coerced to the
36903697
* target output type.
36913698
*/

src/backend/utils/adt/ruleutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10654,7 +10654,7 @@ get_json_constructor(JsonConstructorExpr *ctor, deparse_context *context,
1065410654
funcname = "JSON_ARRAY";
1065510655
break;
1065610656
default:
10657-
elog(ERROR, "invalid JsonConstructorExprType %d", ctor->type);
10657+
elog(ERROR, "invalid JsonConstructorType %d", ctor->type);
1065810658
}
1065910659

1066010660
appendStringInfo(buf, "%s(", funcname);

src/include/nodes/parsenodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ typedef struct JsonObjectAgg
18091809

18101810
/*
18111811
* JsonArrayAgg -
1812-
* untransformed representation of JSON_ARRRAYAGG()
1812+
* untransformed representation of JSON_ARRAYAGG()
18131813
*/
18141814
typedef struct JsonArrayAgg
18151815
{

src/include/nodes/primnodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ typedef struct JsonReturning
15481548

15491549
/*
15501550
* JsonValueExpr -
1551-
* representation of JSON value expression (expr [FORMAT json_format])
1551+
* representation of JSON value expression (expr [FORMAT JsonFormat])
15521552
*/
15531553
typedef struct JsonValueExpr
15541554
{

0 commit comments

Comments
 (0)