MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecEvalFunctionArgToConst

Function ExecEvalFunctionArgToConst

src/backend/executor/execExpr.c:4410–4450  ·  view source on GitHub ↗

* ExecEvalFunctionArgToConst * * Evaluates an argument of function expression and returns the result. * This is assumed to be used in the parser stage, where * dynamic evaluation such like Var is not available, though we put it * here so that we can extend it to be useful in other places later. */

Source from the content-addressed store, hash-verified

4408 * here so that we can extend it to be useful in other places later.
4409 */
4410Datum
4411ExecEvalFunctionArgToConst(FuncExpr *fexpr, int argno, bool *isnull)
4412{
4413 Expr *aexpr;
4414 Oid argtype;
4415 int32 argtypmod;
4416 Oid argcollation;
4417 Const *result;
4418
4419 /* argument number sanity check */
4420 if (argno < 0 || list_length(fexpr->args) <= argno)
4421 elog(ERROR, "invalid argument number found during evaluating function argument");
4422
4423 aexpr = (Expr *) list_nth(fexpr->args, argno);
4424 /*
4425 * Check if the expression can be evaluated in the Const fasion.
4426 */
4427 if (ExecIsExprUnsafeToConst((Node *) aexpr))
4428 ereport(ERROR,
4429 (errcode(ERRCODE_DATA_EXCEPTION),
4430 errmsg("unable to resolve function argument"),
4431 errposition(exprLocation((Node *) aexpr))));
4432
4433 argtype = exprType((Node *) aexpr);
4434 if (!OidIsValid(argtype))
4435 ereport(ERROR,
4436 (errcode(ERRCODE_INDETERMINATE_DATATYPE),
4437 errmsg("unable to resolve function argument type"),
4438 errposition(exprLocation((Node *) aexpr))));
4439 argtypmod = exprTypmod((Node *) aexpr);
4440 argcollation = exprCollation((Node *) aexpr);
4441
4442 result = (Const *) evaluate_expr(aexpr, argtype, argtypmod, argcollation);
4443 /* evaluate_expr always returns Const */
4444 Assert(IsA(result, Const));
4445
4446 if (isnull)
4447 *isnull = result->constisnull;
4448
4449 return result->constvalue;
4450}

Callers 2

project_describeFunction · 0.85
GppcTFGetArgDatumFunction · 0.85

Calls 11

list_lengthFunction · 0.85
list_nthFunction · 0.85
ExecIsExprUnsafeToConstFunction · 0.85
exprLocationFunction · 0.85
exprTypeFunction · 0.85
exprTypmodFunction · 0.85
exprCollationFunction · 0.85
evaluate_exprFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errpositionFunction · 0.50

Tested by 1

project_describeFunction · 0.68