| 2497 | } |
| 2498 | |
| 2499 | static Oid |
| 2500 | findRangeSubtypeDiffFunction(List *procname, Oid subtype) |
| 2501 | { |
| 2502 | Oid argList[2]; |
| 2503 | Oid procOid; |
| 2504 | AclResult aclresult; |
| 2505 | |
| 2506 | /* |
| 2507 | * Range subtype diff functions must take two arguments of the subtype, |
| 2508 | * must return float8, and must be immutable. |
| 2509 | */ |
| 2510 | argList[0] = subtype; |
| 2511 | argList[1] = subtype; |
| 2512 | |
| 2513 | procOid = LookupFuncName(procname, 2, argList, true); |
| 2514 | |
| 2515 | if (!OidIsValid(procOid)) |
| 2516 | ereport(ERROR, |
| 2517 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 2518 | errmsg("function %s does not exist", |
| 2519 | func_signature_string(procname, 2, NIL, argList)))); |
| 2520 | |
| 2521 | if (get_func_rettype(procOid) != FLOAT8OID) |
| 2522 | ereport(ERROR, |
| 2523 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
| 2524 | errmsg("range subtype diff function %s must return type %s", |
| 2525 | func_signature_string(procname, 2, NIL, argList), |
| 2526 | "double precision"))); |
| 2527 | |
| 2528 | if (func_volatile(procOid) != PROVOLATILE_IMMUTABLE) |
| 2529 | ereport(ERROR, |
| 2530 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
| 2531 | errmsg("range subtype diff function %s must be immutable", |
| 2532 | func_signature_string(procname, 2, NIL, argList)))); |
| 2533 | |
| 2534 | /* Also, range type's creator must have permission to call function */ |
| 2535 | aclresult = pg_proc_aclcheck(procOid, GetUserId(), ACL_EXECUTE); |
| 2536 | if (aclresult != ACLCHECK_OK) |
| 2537 | aclcheck_error(aclresult, OBJECT_FUNCTION, get_func_name(procOid)); |
| 2538 | |
| 2539 | return procOid; |
| 2540 | } |
| 2541 | |
| 2542 | /* |
| 2543 | * AssignTypeArrayOid |
no test coverage detected