diff options
Diffstat (limited to 'src/backend/utils/adt/regproc.c')
-rw-r--r-- | src/backend/utils/adt/regproc.c | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index cb11bd0ade6..94599aa44ba 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -41,6 +41,8 @@ #include "utils/syscache.h" #include "utils/tqual.h" +static char *format_operator_internal(Oid operator_oid, bool force_qualify); +static char *format_procedure_internal(Oid procedure_oid, bool force_qualify); static void parseNameAndArgTypes(const char *string, bool allowNone, List **names, int *nargs, Oid *argtypes); @@ -304,6 +306,25 @@ regprocedurein(PG_FUNCTION_ARGS) char * format_procedure(Oid procedure_oid) { + return format_procedure_internal(procedure_oid, false); +} + +char * +format_procedure_qualified(Oid procedure_oid) +{ + return format_procedure_internal(procedure_oid, true); +} + +/* + * Routine to produce regprocedure names; see format_procedure above. + * + * force_qualify says whether to schema-qualify; if true, the name is always + * qualified regardless of search_path visibility. Otherwise the name is only + * qualified if the function is not in path. + */ +static char * +format_procedure_internal(Oid procedure_oid, bool force_qualify) +{ char *result; HeapTuple proctup; @@ -326,7 +347,7 @@ format_procedure(Oid procedure_oid) * Would this proc be found (given the right args) by regprocedurein? * If not, we need to qualify it. */ - if (FunctionIsVisible(procedure_oid)) + if (!force_qualify && FunctionIsVisible(procedure_oid)) nspname = NULL; else nspname = get_namespace_name(procform->pronamespace); @@ -339,7 +360,10 @@ format_procedure(Oid procedure_oid) if (i > 0) appendStringInfoChar(&buf, ','); - appendStringInfoString(&buf, format_type_be(thisargtype)); + appendStringInfoString(&buf, + force_qualify ? + format_type_be_qualified(thisargtype) : + format_type_be(thisargtype)); } appendStringInfoChar(&buf, ')'); @@ -653,8 +677,8 @@ regoperatorin(PG_FUNCTION_ARGS) * This exports the useful functionality of regoperatorout for use * in other backend modules. The result is a palloc'd string. */ -char * -format_operator(Oid operator_oid) +static char * +format_operator_internal(Oid operator_oid, bool force_qualify) { char *result; HeapTuple opertup; @@ -674,9 +698,9 @@ format_operator(Oid operator_oid) /* * Would this oper be found (given the right args) by regoperatorin? - * If not, we need to qualify it. + * If not, or if caller explicitely requests it, we need to qualify it. */ - if (!OperatorIsVisible(operator_oid)) + if (force_qualify || !OperatorIsVisible(operator_oid)) { nspname = get_namespace_name(operform->oprnamespace); appendStringInfo(&buf, "%s.", @@ -687,12 +711,16 @@ format_operator(Oid operator_oid) if (operform->oprleft) appendStringInfo(&buf, "%s,", + force_qualify ? + format_type_be_qualified(operform->oprleft) : format_type_be(operform->oprleft)); else appendStringInfo(&buf, "NONE,"); if (operform->oprright) appendStringInfo(&buf, "%s)", + force_qualify ? + format_type_be_qualified(operform->oprright) : format_type_be(operform->oprright)); else appendStringInfo(&buf, "NONE)"); @@ -713,6 +741,18 @@ format_operator(Oid operator_oid) return result; } +char * +format_operator(Oid operator_oid) +{ + return format_operator_internal(operator_oid, false); +} + +char * +format_operator_qualified(Oid operator_oid) +{ + return format_operator_internal(operator_oid, true); +} + /* * regoperatorout - converts operator OID to "opr_name(args)" */ |