/*
* 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))
{
{
char *role_name_or_oid = PG_GETARG_CSTRING(0);
Oid result;
+ List *names;
/* '-' ? */
if (strcmp(role_name_or_oid, "-") == 0)
}
/* 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);
}
{
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);
Oid roleoid = PG_GETARG_OID(0);
char *result;
-
if (roleoid == InvalidOid)
{
result = pstrdup("-");
}
result = GetUserNameFromId(roleoid, true);
+
if (!result)
{
/* If OID doesn't match any role, return it numerically */
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)
}
/* 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);
}
{
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);
}
result = get_namespace_name(nspid);
+
if (!result)
{
/* If OID doesn't match any namespace, return it numerically */
integer
(1 row)
-SELECT regrole('regtestrole');
- regrole
--------------
- regtestrole
-(1 row)
-
-SELECT regnamespace('pg_catalog');
- regnamespace
---------------
- pg_catalog
-(1 row)
-
SELECT to_regoper('||/');
to_regoper
------------
integer
(1 row)
-SELECT to_regrole('regtestrole');
- to_regrole
--------------
- regtestrole
-(1 row)
-
-SELECT to_regnamespace('pg_catalog');
- to_regnamespace
------------------
- pg_catalog
-(1 row)
-
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
integer
(1 row)
+-- schemaname not applicable
+SELECT regrole('regtestrole');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
+SELECT regrole('"regtestrole"');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
+SELECT regnamespace('pg_catalog');
+ regnamespace
+--------------
+ pg_catalog
+(1 row)
+
+SELECT regnamespace('"pg_catalog"');
+ regnamespace
+--------------
+ pg_catalog
+(1 row)
+
+SELECT to_regrole('regtestrole');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
+SELECT to_regrole('"regtestrole"');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
+SELECT to_regnamespace('pg_catalog');
+ to_regnamespace
+-----------------
+ pg_catalog
+(1 row)
+
+SELECT to_regnamespace('"pg_catalog"');
+ to_regnamespace
+-----------------
+ pg_catalog
+(1 row)
+
/* If objects don't exist, raise errors. */
DROP ROLE regtestrole;
-- without schemaname
ERROR: type "int3" does not exist
LINE 1: SELECT regtype('int3');
^
-SELECT regrole('regtestrole');
-ERROR: role "regtestrole" does not exist
-LINE 1: SELECT regrole('regtestrole');
- ^
-SELECT regnamespace('nonexistent');
-ERROR: schema "nonexistent" does not exist
-LINE 1: SELECT regnamespace('nonexistent');
- ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
ERROR: schema "ng_catalog" does not exist
LINE 1: SELECT regtype('ng_catalog.int4');
^
+-- schemaname not applicable
+SELECT regrole('regtestrole');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('regtestrole');
+ ^
+SELECT regrole('"regtestrole"');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('"regtestrole"');
+ ^
+SELECT regrole('Nonexistent');
+ERROR: role "nonexistent" does not exist
+LINE 1: SELECT regrole('Nonexistent');
+ ^
+SELECT regrole('"Nonexistent"');
+ERROR: role "Nonexistent" does not exist
+LINE 1: SELECT regrole('"Nonexistent"');
+ ^
+SELECT regrole('foo.bar');
+ERROR: invalid name syntax
+LINE 1: SELECT regrole('foo.bar');
+ ^
+SELECT regnamespace('Nonexistent');
+ERROR: schema "nonexistent" does not exist
+LINE 1: SELECT regnamespace('Nonexistent');
+ ^
+SELECT regnamespace('"Nonexistent"');
+ERROR: schema "Nonexistent" does not exist
+LINE 1: SELECT regnamespace('"Nonexistent"');
+ ^
+SELECT regnamespace('foo.bar');
+ERROR: invalid name syntax
+LINE 1: SELECT regnamespace('foo.bar');
+ ^
/* If objects don't exist, return NULL with no error. */
-- without schemaname
SELECT to_regoper('||//');
(1 row)
-SELECT to_regrole('regtestrole');
- to_regrole
-------------
-
-(1 row)
-
-SELECT to_regnamespace('nonexistent');
- to_regnamespace
------------------
-
-(1 row)
-
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
(1 row)
+-- schemaname not applicable
+SELECT to_regrole('regtestrole');
+ to_regrole
+------------
+
+(1 row)
+
+SELECT to_regrole('"regtestrole"');
+ to_regrole
+------------
+
+(1 row)
+
+SELECT to_regrole('foo.bar');
+ERROR: invalid name syntax
+SELECT to_regrole('Nonexistent');
+ to_regrole
+------------
+
+(1 row)
+
+SELECT to_regrole('"Nonexistent"');
+ to_regrole
+------------
+
+(1 row)
+
+SELECT to_regrole('foo.bar');
+ERROR: invalid name syntax
+SELECT to_regnamespace('Nonexistent');
+ to_regnamespace
+-----------------
+
+(1 row)
+
+SELECT to_regnamespace('"Nonexistent"');
+ to_regnamespace
+-----------------
+
+(1 row)
+
+SELECT to_regnamespace('foo.bar');
+ERROR: invalid name syntax
/* If objects exist, return oids */
CREATE ROLE regtestrole;
+
-- without schemaname
SELECT regoper('||/');
SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
-SELECT regrole('regtestrole');
-SELECT regnamespace('pg_catalog');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
-SELECT to_regrole('regtestrole');
-SELECT to_regnamespace('pg_catalog');
-- with schemaname
SELECT to_regclass('pg_catalog.pg_class');
SELECT to_regtype('pg_catalog.int4');
+-- schemaname not applicable
+
+SELECT regrole('regtestrole');
+SELECT regrole('"regtestrole"');
+SELECT regnamespace('pg_catalog');
+SELECT regnamespace('"pg_catalog"');
+
+SELECT to_regrole('regtestrole');
+SELECT to_regrole('"regtestrole"');
+SELECT to_regnamespace('pg_catalog');
+SELECT to_regnamespace('"pg_catalog"');
+
/* If objects don't exist, raise errors. */
DROP ROLE regtestrole;
SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
-SELECT regrole('regtestrole');
-SELECT regnamespace('nonexistent');
-- with schemaname
SELECT regclass('ng_catalog.pg_class');
SELECT regtype('ng_catalog.int4');
+-- schemaname not applicable
+
+SELECT regrole('regtestrole');
+SELECT regrole('"regtestrole"');
+SELECT regrole('Nonexistent');
+SELECT regrole('"Nonexistent"');
+SELECT regrole('foo.bar');
+SELECT regnamespace('Nonexistent');
+SELECT regnamespace('"Nonexistent"');
+SELECT regnamespace('foo.bar');
+
/* If objects don't exist, return NULL with no error. */
-- without schemaname
SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
-SELECT to_regrole('regtestrole');
-SELECT to_regnamespace('nonexistent');
-- with schemaname
SELECT to_regprocedure('ng_catalog.abs(numeric)');
SELECT to_regclass('ng_catalog.pg_class');
SELECT to_regtype('ng_catalog.int4');
+
+-- schemaname not applicable
+
+SELECT to_regrole('regtestrole');
+SELECT to_regrole('"regtestrole"');
+SELECT to_regrole('foo.bar');
+SELECT to_regrole('Nonexistent');
+SELECT to_regrole('"Nonexistent"');
+SELECT to_regrole('foo.bar');
+SELECT to_regnamespace('Nonexistent');
+SELECT to_regnamespace('"Nonexistent"');
+SELECT to_regnamespace('foo.bar');