mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Add pg_identify_object_as_address
This function returns object type and objname/objargs arrays, which can be passed to pg_get_object_address. This is especially useful because the textual representation can be copied to a remote server in order to obtain the corresponding OID-based address. In essence, this function is the inverse of recently added pg_get_object_address(). Catalog version bumped due to the addition of the new function. Also add docs to pg_get_object_address.
This commit is contained in:
@ -438,6 +438,41 @@ format_procedure_internal(Oid procedure_oid, bool force_qualify)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Output a objname/objargs representation for the procedure with the
|
||||
* given OID. If it doesn't exist, an error is thrown.
|
||||
*
|
||||
* This can be used to feed get_object_address.
|
||||
*/
|
||||
void
|
||||
format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs)
|
||||
{
|
||||
HeapTuple proctup;
|
||||
Form_pg_proc procform;
|
||||
int nargs;
|
||||
int i;
|
||||
|
||||
proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procedure_oid));
|
||||
|
||||
if (!HeapTupleIsValid(proctup))
|
||||
elog(ERROR, "cache lookup failed for procedure with OID %u", procedure_oid);
|
||||
|
||||
procform = (Form_pg_proc) GETSTRUCT(proctup);
|
||||
nargs = procform->pronargs;
|
||||
|
||||
*objnames = list_make2(get_namespace_name(procform->pronamespace),
|
||||
pstrdup(NameStr(procform->proname)));
|
||||
*objargs = NIL;
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
Oid thisargtype = procform->proargtypes.values[i];
|
||||
|
||||
*objargs = lappend(*objargs, format_type_be_qualified(thisargtype));
|
||||
}
|
||||
|
||||
ReleaseSysCache(proctup);
|
||||
}
|
||||
|
||||
/*
|
||||
* regprocedureout - converts proc OID to "pro_name(args)"
|
||||
*/
|
||||
@ -875,6 +910,31 @@ format_operator_qualified(Oid operator_oid)
|
||||
return format_operator_internal(operator_oid, true);
|
||||
}
|
||||
|
||||
void
|
||||
format_operator_parts(Oid operator_oid, List **objnames, List **objargs)
|
||||
{
|
||||
HeapTuple opertup;
|
||||
Form_pg_operator oprForm;
|
||||
|
||||
opertup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operator_oid));
|
||||
if (!HeapTupleIsValid(opertup))
|
||||
elog(ERROR, "cache lookup failed for operator with OID %u",
|
||||
operator_oid);
|
||||
|
||||
oprForm = (Form_pg_operator) GETSTRUCT(opertup);
|
||||
*objnames = list_make2(get_namespace_name(oprForm->oprnamespace),
|
||||
pstrdup(NameStr(oprForm->oprname)));
|
||||
*objargs = NIL;
|
||||
if (oprForm->oprleft)
|
||||
*objargs = lappend(*objargs,
|
||||
format_type_be_qualified(oprForm->oprleft));
|
||||
if (oprForm->oprright)
|
||||
*objargs = lappend(*objargs,
|
||||
format_type_be_qualified(oprForm->oprright));
|
||||
|
||||
ReleaseSysCache(opertup);
|
||||
}
|
||||
|
||||
/*
|
||||
* regoperatorout - converts operator OID to "opr_name(args)"
|
||||
*/
|
||||
|
Reference in New Issue
Block a user