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
This commit is contained in:
parent
589bb81649
commit
60966f56c3
@ -4479,10 +4479,7 @@ ExecEvalJsonConstructor(ExprState *state, ExprEvalStep *op,
|
|||||||
jcstate->constructor->absent_on_null,
|
jcstate->constructor->absent_on_null,
|
||||||
jcstate->constructor->unique);
|
jcstate->constructor->unique);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
res = (Datum) 0;
|
|
||||||
elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
|
elog(ERROR, "invalid JsonConstructorExpr type %d", ctor->type);
|
||||||
}
|
|
||||||
|
|
||||||
*op->resvalue = res;
|
*op->resvalue = res;
|
||||||
*op->resnull = isnull;
|
*op->resnull = isnull;
|
||||||
|
@ -3138,7 +3138,7 @@ makeJsonByteaToTextConversion(Node *expr, JsonFormat *format, int location)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make CaseTestExpr node.
|
* Make a CaseTestExpr node.
|
||||||
*/
|
*/
|
||||||
static Node *
|
static Node *
|
||||||
makeCaseTestExpr(Node *expr)
|
makeCaseTestExpr(Node *expr)
|
||||||
@ -3456,6 +3456,9 @@ coerceJsonFuncExpr(ParseState *pstate, Node *expr,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make a JsonConstructorExpr node.
|
||||||
|
*/
|
||||||
static Node *
|
static Node *
|
||||||
makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
|
makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
|
||||||
List *args, Expr *fexpr, JsonReturning *returning,
|
List *args, Expr *fexpr, JsonReturning *returning,
|
||||||
@ -3464,8 +3467,6 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
|
|||||||
JsonConstructorExpr *jsctor = makeNode(JsonConstructorExpr);
|
JsonConstructorExpr *jsctor = makeNode(JsonConstructorExpr);
|
||||||
Node *placeholder;
|
Node *placeholder;
|
||||||
Node *coercion;
|
Node *coercion;
|
||||||
Oid intermediate_typid =
|
|
||||||
returning->format->format_type == JS_FORMAT_JSONB ? JSONBOID : JSONOID;
|
|
||||||
|
|
||||||
jsctor->args = args;
|
jsctor->args = args;
|
||||||
jsctor->func = fexpr;
|
jsctor->func = fexpr;
|
||||||
@ -3481,7 +3482,8 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
|
|||||||
{
|
{
|
||||||
CaseTestExpr *cte = makeNode(CaseTestExpr);
|
CaseTestExpr *cte = makeNode(CaseTestExpr);
|
||||||
|
|
||||||
cte->typeId = intermediate_typid;
|
cte->typeId = returning->format->format_type == JS_FORMAT_JSONB ?
|
||||||
|
JSONBOID : JSONOID;
|
||||||
cte->typeMod = -1;
|
cte->typeMod = -1;
|
||||||
cte->collation = InvalidOid;
|
cte->collation = InvalidOid;
|
||||||
|
|
||||||
@ -3501,7 +3503,7 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type,
|
|||||||
*
|
*
|
||||||
* JSON_OBJECT() is transformed into json[b]_build_object[_ext]() call
|
* JSON_OBJECT() is transformed into json[b]_build_object[_ext]() call
|
||||||
* depending on the output JSON format. The first two arguments of
|
* depending on the output JSON format. The first two arguments of
|
||||||
* json[b]_build_object_ext() are absent_on_null and check_key_uniqueness.
|
* json[b]_build_object_ext() are absent_on_null and check_unique.
|
||||||
*
|
*
|
||||||
* Then function call result is coerced to the target type.
|
* Then function call result is coerced to the target type.
|
||||||
*/
|
*/
|
||||||
@ -3615,9 +3617,11 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
|||||||
{
|
{
|
||||||
Oid aggfnoid;
|
Oid aggfnoid;
|
||||||
Node *node;
|
Node *node;
|
||||||
Expr *aggfilter = agg_ctor->agg_filter ? (Expr *)
|
Expr *aggfilter;
|
||||||
transformWhereClause(pstate, agg_ctor->agg_filter,
|
|
||||||
EXPR_KIND_FILTER, "FILTER") : NULL;
|
aggfilter = agg_ctor->agg_filter ? (Expr *)
|
||||||
|
transformWhereClause(pstate, agg_ctor->agg_filter,
|
||||||
|
EXPR_KIND_FILTER, "FILTER") : NULL;
|
||||||
|
|
||||||
aggfnoid = DatumGetInt32(DirectFunctionCall1(regprocin,
|
aggfnoid = DatumGetInt32(DirectFunctionCall1(regprocin,
|
||||||
CStringGetDatum(aggfn)));
|
CStringGetDatum(aggfn)));
|
||||||
@ -3631,10 +3635,10 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
|||||||
wfunc->wintype = aggtype;
|
wfunc->wintype = aggtype;
|
||||||
/* wincollid and inputcollid will be set by parse_collate.c */
|
/* wincollid and inputcollid will be set by parse_collate.c */
|
||||||
wfunc->args = args;
|
wfunc->args = args;
|
||||||
|
wfunc->aggfilter = aggfilter;
|
||||||
/* winref will be set by transformWindowFuncCall */
|
/* winref will be set by transformWindowFuncCall */
|
||||||
wfunc->winstar = false;
|
wfunc->winstar = false;
|
||||||
wfunc->winagg = true;
|
wfunc->winagg = true;
|
||||||
wfunc->aggfilter = aggfilter;
|
|
||||||
wfunc->location = agg_ctor->location;
|
wfunc->location = agg_ctor->location;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3659,7 +3663,7 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
|||||||
aggref->aggtype = aggtype;
|
aggref->aggtype = aggtype;
|
||||||
|
|
||||||
/* aggcollid and inputcollid will be set by parse_collate.c */
|
/* aggcollid and inputcollid will be set by parse_collate.c */
|
||||||
aggref->aggtranstype = InvalidOid; /* will be set by planner */
|
/* aggtranstype will be set by planner */
|
||||||
/* aggargtypes will be set by transformAggregateCall */
|
/* aggargtypes will be set by transformAggregateCall */
|
||||||
/* aggdirectargs and args will be set by transformAggregateCall */
|
/* aggdirectargs and args will be set by transformAggregateCall */
|
||||||
/* aggorder and aggdistinct will be set by transformAggregateCall */
|
/* aggorder and aggdistinct will be set by transformAggregateCall */
|
||||||
@ -3667,8 +3671,11 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
|||||||
aggref->aggstar = false;
|
aggref->aggstar = false;
|
||||||
aggref->aggvariadic = false;
|
aggref->aggvariadic = false;
|
||||||
aggref->aggkind = AGGKIND_NORMAL;
|
aggref->aggkind = AGGKIND_NORMAL;
|
||||||
|
aggref->aggpresorted = false;
|
||||||
/* agglevelsup will be set by transformAggregateCall */
|
/* agglevelsup will be set by transformAggregateCall */
|
||||||
aggref->aggsplit = AGGSPLIT_SIMPLE; /* planner might change this */
|
aggref->aggsplit = AGGSPLIT_SIMPLE; /* planner might change this */
|
||||||
|
aggref->aggno = -1; /* planner will set aggno and aggtransno */
|
||||||
|
aggref->aggtransno = -1;
|
||||||
aggref->location = agg_ctor->location;
|
aggref->location = agg_ctor->location;
|
||||||
|
|
||||||
transformAggregateCall(pstate, aggref, args, agg_ctor->agg_order, false);
|
transformAggregateCall(pstate, aggref, args, agg_ctor->agg_order, false);
|
||||||
@ -3685,7 +3692,7 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor,
|
|||||||
* Transform JSON_OBJECTAGG() aggregate function.
|
* Transform JSON_OBJECTAGG() aggregate function.
|
||||||
*
|
*
|
||||||
* JSON_OBJECTAGG() is transformed into
|
* JSON_OBJECTAGG() is transformed into
|
||||||
* json[b]_objectagg(key, value, absent_on_null, check_unique) call depending on
|
* json[b]_objectagg[_unique][_strict](key, value) call depending on
|
||||||
* the output JSON format. Then the function call result is coerced to the
|
* the output JSON format. Then the function call result is coerced to the
|
||||||
* target output type.
|
* target output type.
|
||||||
*/
|
*/
|
||||||
|
@ -10654,7 +10654,7 @@ get_json_constructor(JsonConstructorExpr *ctor, deparse_context *context,
|
|||||||
funcname = "JSON_ARRAY";
|
funcname = "JSON_ARRAY";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
elog(ERROR, "invalid JsonConstructorExprType %d", ctor->type);
|
elog(ERROR, "invalid JsonConstructorType %d", ctor->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendStringInfo(buf, "%s(", funcname);
|
appendStringInfo(buf, "%s(", funcname);
|
||||||
|
@ -1809,7 +1809,7 @@ typedef struct JsonObjectAgg
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* JsonArrayAgg -
|
* JsonArrayAgg -
|
||||||
* untransformed representation of JSON_ARRRAYAGG()
|
* untransformed representation of JSON_ARRAYAGG()
|
||||||
*/
|
*/
|
||||||
typedef struct JsonArrayAgg
|
typedef struct JsonArrayAgg
|
||||||
{
|
{
|
||||||
|
@ -1548,7 +1548,7 @@ typedef struct JsonReturning
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* JsonValueExpr -
|
* JsonValueExpr -
|
||||||
* representation of JSON value expression (expr [FORMAT json_format])
|
* representation of JSON value expression (expr [FORMAT JsonFormat])
|
||||||
*/
|
*/
|
||||||
typedef struct JsonValueExpr
|
typedef struct JsonValueExpr
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user