mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Fix regrole and regnamespace types to honor quoting like other reg* types.
Aside from any consistency arguments, this is logically necessary because the I/O functions for these types also handle numeric OID values. Without a quoting rule it is impossible to distinguish numeric OIDs from role or namespace names that happen to contain only digits. Also change the to_regrole and to_regnamespace functions to dequote their arguments. While not logically essential, this seems like a good idea since the other to_reg* functions do it. Anyone who really wants raw lookup of an uninterpreted name can fall back on the time-honored solution of (SELECT oid FROM pg_namespace WHERE nspname = whatever). Report and patch by Jim Nasby, reviewed by Michael Paquier
This commit is contained in:
@ -855,8 +855,7 @@ format_operator_internal(Oid operator_oid, bool force_qualify)
|
||||
|
||||
/*
|
||||
* Would this oper be found (given the right args) by regoperatorin?
|
||||
* If not, or if caller explicitly requests it, we need to qualify
|
||||
* it.
|
||||
* If not, or if caller explicitly requests it, we need to qualify it.
|
||||
*/
|
||||
if (force_qualify || !OperatorIsVisible(operator_oid))
|
||||
{
|
||||
@ -1570,6 +1569,7 @@ regrolein(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *role_name_or_oid = PG_GETARG_CSTRING(0);
|
||||
Oid result;
|
||||
List *names;
|
||||
|
||||
/* '-' ? */
|
||||
if (strcmp(role_name_or_oid, "-") == 0)
|
||||
@ -1586,7 +1586,14 @@ regrolein(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
/* Normal case: see if the name matches any pg_authid entry. */
|
||||
result = get_role_oid(role_name_or_oid, false);
|
||||
names = stringToQualifiedNameList(role_name_or_oid);
|
||||
|
||||
if (list_length(names) != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_NAME),
|
||||
errmsg("invalid name syntax")));
|
||||
|
||||
result = get_role_oid(strVal(linitial(names)), false);
|
||||
|
||||
PG_RETURN_OID(result);
|
||||
}
|
||||
@ -1601,8 +1608,16 @@ to_regrole(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *role_name = PG_GETARG_CSTRING(0);
|
||||
Oid result;
|
||||
List *names;
|
||||
|
||||
result = get_role_oid(role_name, true);
|
||||
names = stringToQualifiedNameList(role_name);
|
||||
|
||||
if (list_length(names) != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_NAME),
|
||||
errmsg("invalid name syntax")));
|
||||
|
||||
result = get_role_oid(strVal(linitial(names)), true);
|
||||
|
||||
if (OidIsValid(result))
|
||||
PG_RETURN_OID(result);
|
||||
@ -1619,7 +1634,6 @@ regroleout(PG_FUNCTION_ARGS)
|
||||
Oid roleoid = PG_GETARG_OID(0);
|
||||
char *result;
|
||||
|
||||
|
||||
if (roleoid == InvalidOid)
|
||||
{
|
||||
result = pstrdup("-");
|
||||
@ -1627,6 +1641,7 @@ regroleout(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
result = GetUserNameFromId(roleoid, true);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* If OID doesn't match any role, return it numerically */
|
||||
@ -1668,7 +1683,8 @@ Datum
|
||||
regnamespacein(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
|
||||
Oid result = InvalidOid;
|
||||
Oid result;
|
||||
List *names;
|
||||
|
||||
/* '-' ? */
|
||||
if (strcmp(nsp_name_or_oid, "-") == 0)
|
||||
@ -1685,7 +1701,14 @@ regnamespacein(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
/* Normal case: see if the name matches any pg_namespace entry. */
|
||||
result = get_namespace_oid(nsp_name_or_oid, false);
|
||||
names = stringToQualifiedNameList(nsp_name_or_oid);
|
||||
|
||||
if (list_length(names) != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_NAME),
|
||||
errmsg("invalid name syntax")));
|
||||
|
||||
result = get_namespace_oid(strVal(linitial(names)), false);
|
||||
|
||||
PG_RETURN_OID(result);
|
||||
}
|
||||
@ -1700,8 +1723,16 @@ to_regnamespace(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *nsp_name = PG_GETARG_CSTRING(0);
|
||||
Oid result;
|
||||
List *names;
|
||||
|
||||
result = get_namespace_oid(nsp_name, true);
|
||||
names = stringToQualifiedNameList(nsp_name);
|
||||
|
||||
if (list_length(names) != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_NAME),
|
||||
errmsg("invalid name syntax")));
|
||||
|
||||
result = get_namespace_oid(strVal(linitial(names)), true);
|
||||
|
||||
if (OidIsValid(result))
|
||||
PG_RETURN_OID(result);
|
||||
@ -1725,6 +1756,7 @@ regnamespaceout(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
result = get_namespace_name(nspid);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
/* If OID doesn't match any namespace, return it numerically */
|
||||
|
Reference in New Issue
Block a user