* 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. */
| 266 | * polymorphic arguments. |
| 267 | */ |
| 268 | SQLFunctionParseInfoPtr |
| 269 | prepare_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; |
no test coverage detected