diff options
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r-- | src/backend/parser/parse_expr.c | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index c1f194cc5b0..17709c3416b 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -3277,7 +3277,7 @@ transformJsonValueExprExt(ParseState *pstate, JsonValueExpr *ve, if (exprtype == JSONOID || exprtype == JSONBOID) { - format = JS_FORMAT_DEFAULT; /* do not format json[b] types */ + format = JS_FORMAT_DEFAULT; /* do not format json[b] types */ ereport(WARNING, (errmsg("FORMAT JSON has no effect for json and jsonb types"), parser_errposition(pstate, ve->format->location))); @@ -3316,7 +3316,7 @@ transformJsonValueExprExt(ParseState *pstate, JsonValueExpr *ve, format = default_format; } else if (exprtype == JSONOID || exprtype == JSONBOID) - format = JS_FORMAT_DEFAULT; /* do not format json[b] types */ + format = JS_FORMAT_DEFAULT; /* do not format json[b] types */ else format = default_format; @@ -3364,13 +3364,13 @@ transformJsonValueExprExt(ParseState *pstate, JsonValueExpr *ve, FuncExpr *fexpr; Oid fnoid; - if (cast_is_needed) /* only CAST is allowed */ + if (cast_is_needed) /* only CAST is allowed */ ereport(ERROR, (errcode(ERRCODE_CANNOT_COERCE), errmsg("cannot cast type %s to %s", format_type_be(exprtype), format_type_be(targettype)), - parser_errposition(pstate, location))); + parser_errposition(pstate, location))); fnoid = targettype == JSONOID ? F_TO_JSON : F_TO_JSONB; fexpr = makeFuncExpr(fnoid, targettype, list_make1(expr), @@ -3444,7 +3444,7 @@ checkJsonOutputFormat(ParseState *pstate, const JsonFormat *format, if (format->format_type == JS_FORMAT_JSON) { JsonEncoding enc = format->encoding != JS_ENC_DEFAULT ? - format->encoding : JS_ENC_UTF8; + format->encoding : JS_ENC_UTF8; if (targettype != BYTEAOID && format->encoding != JS_ENC_DEFAULT) @@ -3583,6 +3583,7 @@ coerceJsonFuncExpr(ParseState *pstate, Node *expr, list_make2(texpr, enc), InvalidOid, InvalidOid, COERCE_EXPLICIT_CALL); + fexpr->location = location; return (Node *) fexpr; @@ -3591,7 +3592,7 @@ coerceJsonFuncExpr(ParseState *pstate, Node *expr, /* try to coerce expression to the output type */ res = coerce_to_target_type(pstate, expr, exprtype, returning->typid, returning->typmod, - /* XXX throwing errors when casting to char(N) */ + /* XXX throwing errors when casting to char(N) */ COERCION_EXPLICIT, COERCE_EXPLICIT_CAST, location); @@ -3616,7 +3617,7 @@ makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type, Node *placeholder; Node *coercion; Oid intermediate_typid = - returning->format->format_type == JS_FORMAT_JSONB ? JSONBOID : JSONOID; + returning->format->format_type == JS_FORMAT_JSONB ? JSONBOID : JSONOID; jsctor->args = args; jsctor->func = fexpr; @@ -3694,7 +3695,7 @@ static Node * transformJsonArrayQueryConstructor(ParseState *pstate, JsonArrayQueryConstructor *ctor) { - SubLink *sublink = makeNode(SubLink); + SubLink *sublink = makeNode(SubLink); SelectStmt *select = makeNode(SelectStmt); RangeSubselect *range = makeNode(RangeSubselect); Alias *alias = makeNode(Alias); @@ -3766,8 +3767,8 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor, Oid aggfnoid; Node *node; Expr *aggfilter = agg_ctor->agg_filter ? (Expr *) - transformWhereClause(pstate, agg_ctor->agg_filter, - EXPR_KIND_FILTER, "FILTER") : NULL; + transformWhereClause(pstate, agg_ctor->agg_filter, + EXPR_KIND_FILTER, "FILTER") : NULL; aggfnoid = DatumGetInt32(DirectFunctionCall1(regprocin, CStringGetDatum(aggfn))); @@ -3809,7 +3810,7 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor, aggref->aggtype = aggtype; /* aggcollid and inputcollid will be set by parse_collate.c */ - aggref->aggtranstype = InvalidOid; /* will be set by planner */ + aggref->aggtranstype = InvalidOid; /* will be set by planner */ /* aggargtypes will be set by transformAggregateCall */ /* aggdirectargs and args will be set by transformAggregateCall */ /* aggorder and aggdistinct will be set by transformAggregateCall */ @@ -3818,7 +3819,7 @@ transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor, aggref->aggvariadic = false; aggref->aggkind = AGGKIND_NORMAL; /* agglevelsup will be set by transformAggregateCall */ - aggref->aggsplit = AGGSPLIT_SIMPLE; /* planner might change this */ + aggref->aggsplit = AGGSPLIT_SIMPLE; /* planner might change this */ aggref->location = agg_ctor->location; transformAggregateCall(pstate, aggref, args, agg_ctor->agg_order, false); @@ -3860,14 +3861,13 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg) { if (agg->absent_on_null) if (agg->unique) - aggfnname = "pg_catalog.jsonb_object_agg_unique_strict"; /* F_JSONB_OBJECT_AGG_UNIQUE_STRICT */ + aggfnname = "pg_catalog.jsonb_object_agg_unique_strict"; /* F_JSONB_OBJECT_AGG_UNIQUE_STRICT */ else - aggfnname = "pg_catalog.jsonb_object_agg_strict"; /* F_JSONB_OBJECT_AGG_STRICT */ + aggfnname = "pg_catalog.jsonb_object_agg_strict"; /* F_JSONB_OBJECT_AGG_STRICT */ + else if (agg->unique) + aggfnname = "pg_catalog.jsonb_object_agg_unique"; /* F_JSONB_OBJECT_AGG_UNIQUE */ else - if (agg->unique) - aggfnname = "pg_catalog.jsonb_object_agg_unique"; /* F_JSONB_OBJECT_AGG_UNIQUE */ - else - aggfnname = "pg_catalog.jsonb_object_agg"; /* F_JSONB_OBJECT_AGG */ + aggfnname = "pg_catalog.jsonb_object_agg"; /* F_JSONB_OBJECT_AGG */ aggtype = JSONBOID; } @@ -3877,12 +3877,11 @@ transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg) if (agg->unique) aggfnname = "pg_catalog.json_object_agg_unique_strict"; /* F_JSON_OBJECT_AGG_UNIQUE_STRICT */ else - aggfnname = "pg_catalog.json_object_agg_strict"; /* F_JSON_OBJECT_AGG_STRICT */ + aggfnname = "pg_catalog.json_object_agg_strict"; /* F_JSON_OBJECT_AGG_STRICT */ + else if (agg->unique) + aggfnname = "pg_catalog.json_object_agg_unique"; /* F_JSON_OBJECT_AGG_UNIQUE */ else - if (agg->unique) - aggfnname = "pg_catalog.json_object_agg_unique"; /* F_JSON_OBJECT_AGG_UNIQUE */ - else - aggfnname = "pg_catalog.json_object_agg"; /* F_JSON_OBJECT_AGG */ + aggfnname = "pg_catalog.json_object_agg"; /* F_JSON_OBJECT_AGG */ aggtype = JSONOID; } @@ -4209,7 +4208,7 @@ coerceJsonExpr(ParseState *pstate, Node *expr, const JsonReturning *returning) * Transform a JSON output clause of JSON_VALUE and JSON_QUERY. */ static void -transformJsonFuncExprOutput(ParseState *pstate, JsonFuncExpr *func, +transformJsonFuncExprOutput(ParseState *pstate, JsonFuncExpr *func, JsonExpr *jsexpr) { Node *expr = jsexpr->formatted_expr; @@ -4333,19 +4332,19 @@ initJsonItemCoercions(ParseState *pstate, JsonItemCoercions *coercions, Oid typid; } *p, coercionTypids[] = - { - { &coercions->null, UNKNOWNOID }, - { &coercions->string, TEXTOID }, - { &coercions->numeric, NUMERICOID }, - { &coercions->boolean, BOOLOID }, - { &coercions->date, DATEOID }, - { &coercions->time, TIMEOID }, - { &coercions->timetz, TIMETZOID }, - { &coercions->timestamp, TIMESTAMPOID }, - { &coercions->timestamptz, TIMESTAMPTZOID }, - { &coercions->composite, contextItemTypeId }, - { NULL, InvalidOid } - }; + { + {&coercions->null, UNKNOWNOID}, + {&coercions->string, TEXTOID}, + {&coercions->numeric, NUMERICOID}, + {&coercions->boolean, BOOLOID}, + {&coercions->date, DATEOID}, + {&coercions->time, TIMEOID}, + {&coercions->timetz, TIMETZOID}, + {&coercions->timestamp, TIMESTAMPOID}, + {&coercions->timestamptz, TIMESTAMPTZOID}, + {&coercions->composite, contextItemTypeId}, + {NULL, InvalidOid} + }; for (p = coercionTypids; p->coercion; p++) *p->coercion = initJsonItemCoercion(pstate, p->typid, returning); @@ -4512,7 +4511,7 @@ static Node * transformJsonParseExpr(ParseState *pstate, JsonParseExpr *jsexpr) { JsonReturning *returning = transformJsonConstructorRet(pstate, jsexpr->output, - "JSON()"); + "JSON()"); Node *arg; if (jsexpr->unique_keys) @@ -4544,8 +4543,8 @@ transformJsonParseExpr(ParseState *pstate, JsonParseExpr *jsexpr) } return makeJsonConstructorExpr(pstate, JSCTOR_JSON_PARSE, list_make1(arg), NULL, - returning, jsexpr->unique_keys, false, - jsexpr->location); + returning, jsexpr->unique_keys, false, + jsexpr->location); } /* @@ -4556,13 +4555,13 @@ transformJsonScalarExpr(ParseState *pstate, JsonScalarExpr *jsexpr) { Node *arg = transformExprRecurse(pstate, (Node *) jsexpr->expr); JsonReturning *returning = transformJsonConstructorRet(pstate, jsexpr->output, - "JSON_SCALAR()"); + "JSON_SCALAR()"); if (exprType(arg) == UNKNOWNOID) arg = coerce_to_specific_type(pstate, arg, TEXTOID, "JSON_SCALAR"); return makeJsonConstructorExpr(pstate, JSCTOR_JSON_SCALAR, list_make1(arg), NULL, - returning, false, false, jsexpr->location); + returning, false, false, jsexpr->location); } /* @@ -4586,5 +4585,5 @@ transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr) } return makeJsonConstructorExpr(pstate, JSCTOR_JSON_SERIALIZE, list_make1(arg), - NULL, returning, false, false, expr->location); + NULL, returning, false, false, expr->location); } |