mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Add to_regprocedure() and to_regoperator().
These are natural complements to the functions added by commit
0886fc6a5c, but they weren't included
in the original patch for some reason. Add them.
Patch by me, per a complaint by Tom Lane. Review by Tatsuo
Ishii.
This commit is contained in:
@@ -322,6 +322,38 @@ regprocedurein(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_OID(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* to_regprocedure - converts "proname(args)" to proc OID
|
||||
*
|
||||
* If the name is not found, we return NULL.
|
||||
*/
|
||||
Datum
|
||||
to_regprocedure(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *pro_name = PG_GETARG_CSTRING(0);
|
||||
List *names;
|
||||
int nargs;
|
||||
Oid argtypes[FUNC_MAX_ARGS];
|
||||
FuncCandidateList clist;
|
||||
|
||||
/*
|
||||
* Parse the name and arguments, look up potential matches in the current
|
||||
* namespace search list, and scan to see which one exactly matches the
|
||||
* given argument types. (There will not be more than one match.)
|
||||
*/
|
||||
parseNameAndArgTypes(pro_name, false, &names, &nargs, argtypes);
|
||||
|
||||
clist = FuncnameGetCandidates(names, nargs, NIL, false, false, true);
|
||||
|
||||
for (; clist; clist = clist->next)
|
||||
{
|
||||
if (memcmp(clist->args, argtypes, nargs * sizeof(Oid)) == 0)
|
||||
PG_RETURN_OID(clist->oid);
|
||||
}
|
||||
|
||||
PG_RETURN_NULL();
|
||||
}
|
||||
|
||||
/*
|
||||
* format_procedure - converts proc OID to "pro_name(args)"
|
||||
*
|
||||
@@ -721,6 +753,45 @@ regoperatorin(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_OID(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* to_regoperator - converts "oprname(args)" to operator OID
|
||||
*
|
||||
* If the name is not found, we return NULL.
|
||||
*/
|
||||
Datum
|
||||
to_regoperator(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *opr_name_or_oid = PG_GETARG_CSTRING(0);
|
||||
Oid result;
|
||||
List *names;
|
||||
int nargs;
|
||||
Oid argtypes[FUNC_MAX_ARGS];
|
||||
|
||||
/*
|
||||
* Parse the name and arguments, look up potential matches in the current
|
||||
* namespace search list, and scan to see which one exactly matches the
|
||||
* given argument types. (There will not be more than one match.)
|
||||
*/
|
||||
parseNameAndArgTypes(opr_name_or_oid, true, &names, &nargs, argtypes);
|
||||
if (nargs == 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_PARAMETER),
|
||||
errmsg("missing argument"),
|
||||
errhint("Use NONE to denote the missing argument of a unary operator.")));
|
||||
if (nargs != 2)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
|
||||
errmsg("too many arguments"),
|
||||
errhint("Provide two argument types for operator.")));
|
||||
|
||||
result = OpernameGetOprid(names, argtypes[0], argtypes[1]);
|
||||
|
||||
if (!OidIsValid(result))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
PG_RETURN_OID(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* format_operator - converts operator OID to "opr_name(args)"
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user