/* We support only single-subscript, non-slice cases */ if (isSlice || list_length(indirection) != 1)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hstore allows only one subscript"),
parser_errposition(pstate,
exprLocation((Node *) indirection))));
/* Transform the subscript expression to type text */
ai = linitial_node(A_Indices, indirection);
Assert(ai->uidx != NULL && ai->lidx == NULL && !ai->is_slice);
subexpr = transformExpr(pstate, ai->uidx, pstate->p_expr_kind); /* If it's not text already, try to coerce */
subexpr = coerce_to_target_type(pstate,
subexpr, exprType(subexpr),
TEXTOID, -1,
COERCION_ASSIGNMENT,
COERCE_IMPLICIT_CAST,
-1); if (subexpr == NULL)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("hstore subscript must have type text"),
parser_errposition(pstate, exprLocation(ai->uidx))));
/* ... and store the transformed subscript into the SubscriptRef node */
sbsref->refupperindexpr = list_make1(subexpr);
sbsref->reflowerindexpr = NIL;
/* Determine the result type of the subscripting operation; always text */
sbsref->refrestype = TEXTOID;
sbsref->reftypmod = -1;
}
/* *EvaluateSubscriptingReffetchforhstore. * *Sourcecontainerisinstep'sresultvariable(it'sknownnotNULL,since *wesetfetch_stricttotrue),andthesubscriptexpressionisinthe *upperindex[]array.
*/ staticvoid
hstore_subscript_fetch(ExprState *state,
ExprEvalStep *op,
ExprContext *econtext)
{
SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
HStore *hs;
text *key;
HEntry *entries; int idx;
text *out;
/* Should not get here if source hstore is null */
Assert(!(*op->resnull));
/* Check for null subscript */ if (sbsrefstate->upperindexnull[0])
{
*op->resnull = true; return;
}
/* OK, fetch/detoast the hstore and subscript */
hs = DatumGetHStoreP(*op->resvalue);
key = DatumGetTextPP(sbsrefstate->upperindex[0]);
/* The rest is basically the same as hstore_fetchval() */
entries = ARRPTR(hs);
idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
/* Check for null subscript */ if (sbsrefstate->upperindexnull[0])
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("hstore subscript in assignment must not be null")));
/* OK, fetch/detoast the subscript */
key = DatumGetTextPP(sbsrefstate->upperindex[0]);
/* Create a Pairs entry for subscript + replacement value */
p.needfree = false;
p.key = VARDATA_ANY(key);
p.keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(key));
if (sbsrefstate->replacenull)
{
p.vallen = 0;
p.isnull = true;
} else
{
text *val = DatumGetTextPP(sbsrefstate->replacevalue);
/* *Setupexecutionstateforanhstoresubscriptoperation.
*/ staticvoid
hstore_exec_setup(const SubscriptingRef *sbsref,
SubscriptingRefState *sbsrefstate,
SubscriptExecSteps *methods)
{ /* Assert we are dealing with one subscript */
Assert(sbsrefstate->numlower == 0);
Assert(sbsrefstate->numupper == 1); /* We can't check upperprovided[0] here, but it must be true */
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.