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

Function prepare_sql_fn_parse_info

src/backend/executor/functions.c:268–352  ·  view source on GitHub ↗

* Prepare the SQLFunctionParseInfo struct for parsing a SQL function body * * This includes resolving actual types of polymorphic arguments. * * call_expr can be passed as NULL, but then we will fail if there are any * polymorphic arguments. */

Source from the content-addressed store, hash-verified

266 * polymorphic arguments.
267 */
268SQLFunctionParseInfoPtr
269prepare_sql_fn_parse_info(HeapTuple procedureTuple,
270 Node *call_expr,
271 Oid inputCollation)
272{
273 SQLFunctionParseInfoPtr pinfo;
274 Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
275 int nargs;
276
277 pinfo = (SQLFunctionParseInfoPtr) palloc0(sizeof(SQLFunctionParseInfo));
278
279 /* Function's name (only) can be used to qualify argument names */
280 pinfo->fname = pstrdup(NameStr(procedureStruct->proname));
281
282 /* Save the function's input collation */
283 pinfo->collation = inputCollation;
284
285 /*
286 * Copy input argument types from the pg_proc entry, then resolve any
287 * polymorphic types.
288 */
289 pinfo->nargs = nargs = procedureStruct->pronargs;
290 if (nargs > 0)
291 {
292 Oid *argOidVect;
293 int argnum;
294
295 argOidVect = (Oid *) palloc(nargs * sizeof(Oid));
296 memcpy(argOidVect,
297 procedureStruct->proargtypes.values,
298 nargs * sizeof(Oid));
299
300 for (argnum = 0; argnum < nargs; argnum++)
301 {
302 Oid argtype = argOidVect[argnum];
303
304 if (IsPolymorphicType(argtype))
305 {
306 argtype = get_call_expr_argtype(call_expr, argnum);
307 if (argtype == InvalidOid)
308 ereport(ERROR,
309 (errcode(ERRCODE_DATATYPE_MISMATCH),
310 errmsg("could not determine actual type of argument declared %s",
311 format_type_be(argOidVect[argnum]))));
312 argOidVect[argnum] = argtype;
313 }
314 }
315
316 pinfo->argtypes = argOidVect;
317 }
318
319 /*
320 * Collect names of arguments, too, if any
321 */
322 if (nargs > 0)
323 {
324 Datum proargnames;
325 Datum proargmodes;

Callers 4

init_sql_fcacheFunction · 0.85
inline_functionFunction · 0.85
fmgr_sql_validatorFunction · 0.85

Calls 9

get_call_expr_argtypeFunction · 0.85
format_type_beFunction · 0.85
SysCacheGetAttrFunction · 0.85
get_func_input_arg_namesFunction · 0.85
palloc0Function · 0.50
pstrdupFunction · 0.50
pallocFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected