/* SubscriptingRefState.workspace for jsonb subscripting execution */ typedefstruct JsonbSubWorkspace
{ bool expectArray; /* jsonb root is expected to be an array */
Oid *indexOid; /* OID of coerced subscript expression, could
* be only integer or text */
Datum *index; /* Subscript values in Datum format */
} JsonbSubWorkspace;
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("jsonb subscript does not support slices"),
parser_errposition(pstate, exprLocation(expr))));
}
if (ai->uidx)
{
Oid subExprType = InvalidOid,
targetType = UNKNOWNOID;
if (subExprType != UNKNOWNOID)
{
Oid targets[2] = {INT4OID, TEXTOID};
/* *Jsonbcanhandlemultiplesubscripttypes,butcaseswhena *subscriptcouldbecoercedtomultipletargettypesmustbe *avoided,similartooverloadedfunctions.Itcouldbe *possiblyextendwithjsonpathinthefuture.
*/ for (int i = 0; i < 2; i++)
{ if (can_coerce_type(1, &subExprType, &targets[i], COERCION_IMPLICIT))
{ /* *Onetypehasalreadysucceeded,itmeansthereare *twocoerciontargetspossible,failure.
*/ if (targetType != UNKNOWNOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("subscript type %s is not supported", format_type_be(subExprType)),
errhint("jsonb subscript must be coercible to only one type, integer or text."),
parser_errposition(pstate, exprLocation(subExpr))));
targetType = targets[i];
}
}
/* *Nosuitabletypeswerefound,failure.
*/ if (targetType == UNKNOWNOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("subscript type %s is not supported", format_type_be(subExprType)),
errhint("jsonb subscript must be coercible to either integer or text."),
parser_errposition(pstate, exprLocation(subExpr))));
} else
targetType = TEXTOID;
/* *Weknownfromcan_coerce_typethatcoercionwillsucceed,so *coerce_typecouldbeused.Notetheimplicitcoercioncontext, *whichisrequiredtohandlesubscriptsofdifferenttypes, *similartooverloadedfunctions.
*/
subExpr = coerce_type(pstate,
subExpr, subExprType,
targetType, -1,
COERCION_IMPLICIT,
COERCE_IMPLICIT_CAST,
-1); if (subExpr == NULL)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("jsonb subscript must have text type"),
parser_errposition(pstate, exprLocation(subExpr))));
} else
{ /* *Slicewithomittedupperbound.Shouldnothappenaswealready *erroredoutonsliceearlier,buthandlethisjustincase.
*/
Assert(isSlice && ai->is_slice);
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("jsonb subscript does not support slices"),
parser_errposition(pstate, exprLocation(ai->uidx))));
}
upperIndexpr = lappend(upperIndexpr, subExpr);
}
/* store the transformed lists into the SubscriptRef node */
sbsref->refupperindexpr = upperIndexpr;
sbsref->reflowerindexpr = NIL;
/* Determine the result type of the subscripting operation; always jsonb */
sbsref->refrestype = JSONBOID;
sbsref->reftypmod = -1;
}
/* Process upper subscripts */ for (int i = 0; i < sbsrefstate->numupper; i++)
{ if (sbsrefstate->upperprovided[i])
{ /* If any index expr yields NULL, result is NULL or error */ if (sbsrefstate->upperindexnull[i])
{ if (sbsrefstate->isassignment)
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("jsonb subscript in assignment must not be null")));
*op->resnull = true; returnfalse;
}
/* *Forjsonbfetchandassignfunctionsweneedtoprovidepathin *textformat.Convertifit'snotalreadytext.
*/ if (workspace->indexOid[i] == INT4OID)
{
Datum datum = sbsrefstate->upperindex[i]; char *cs = DatumGetCString(DirectFunctionCall1(int4out, datum));
*op->resvalue = jsonb_set_element(jsonbSource,
workspace->index,
sbsrefstate->numupper,
&replacevalue); /* The result is never NULL, so no need to change *op->resnull */
}
if (*op->resnull)
{ /* whole jsonb is null, so any element is too */
sbsrefstate->prevvalue = (Datum) 0;
sbsrefstate->prevnull = true;
} else
{
Jsonb *jsonbSource = DatumGetJsonbP(*op->resvalue);
/* Collect subscript data types necessary at execution time */
foreach(lc, sbsref->refupperindexpr)
{
Node *expr = lfirst(lc); int i = foreach_current_index(lc);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.