| 447 | PG_FUNCTION_INFO_V1(plpgsql_validator); |
| 448 | |
| 449 | Datum |
| 450 | plpgsql_validator(PG_FUNCTION_ARGS) |
| 451 | { |
| 452 | Oid funcoid = PG_GETARG_OID(0); |
| 453 | HeapTuple tuple; |
| 454 | Form_pg_proc proc; |
| 455 | char functyptype; |
| 456 | int numargs; |
| 457 | Oid *argtypes; |
| 458 | char **argnames; |
| 459 | char *argmodes; |
| 460 | bool is_dml_trigger = false; |
| 461 | bool is_event_trigger = false; |
| 462 | int i; |
| 463 | |
| 464 | if (!CheckFunctionValidatorAccess(fcinfo->flinfo->fn_oid, funcoid)) |
| 465 | PG_RETURN_VOID(); |
| 466 | |
| 467 | /* Get the new function's pg_proc entry */ |
| 468 | tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid)); |
| 469 | if (!HeapTupleIsValid(tuple)) |
| 470 | elog(ERROR, "cache lookup failed for function %u", funcoid); |
| 471 | proc = (Form_pg_proc) GETSTRUCT(tuple); |
| 472 | |
| 473 | functyptype = get_typtype(proc->prorettype); |
| 474 | |
| 475 | /* Disallow pseudotype result */ |
| 476 | /* except for TRIGGER, EVTTRIGGER, RECORD, VOID, or polymorphic */ |
| 477 | if (functyptype == TYPTYPE_PSEUDO) |
| 478 | { |
| 479 | if (proc->prorettype == TRIGGEROID) |
| 480 | is_dml_trigger = true; |
| 481 | else if (proc->prorettype == EVENT_TRIGGEROID) |
| 482 | is_event_trigger = true; |
| 483 | else if (proc->prorettype != RECORDOID && |
| 484 | proc->prorettype != VOIDOID && |
| 485 | !IsPolymorphicType(proc->prorettype)) |
| 486 | ereport(ERROR, |
| 487 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 488 | errmsg("PL/pgSQL functions cannot return type %s", |
| 489 | format_type_be(proc->prorettype)))); |
| 490 | } |
| 491 | |
| 492 | /* Disallow pseudotypes in arguments (either IN or OUT) */ |
| 493 | /* except for RECORD and polymorphic */ |
| 494 | numargs = get_func_arg_info(tuple, |
| 495 | &argtypes, &argnames, &argmodes); |
| 496 | for (i = 0; i < numargs; i++) |
| 497 | { |
| 498 | if (get_typtype(argtypes[i]) == TYPTYPE_PSEUDO) |
| 499 | { |
| 500 | if (argtypes[i] != RECORDOID && |
| 501 | !IsPolymorphicType(argtypes[i])) |
| 502 | ereport(ERROR, |
| 503 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 504 | errmsg("PL/pgSQL functions cannot accept type %s", |
| 505 | format_type_be(argtypes[i])))); |
| 506 | } |
nothing calls this directly
no test coverage detected