On 1/3/16 9:43 PM, Tom Lane wrote:
Jim Nasby <jim.na...@bluetreble.com> writes:
On 1/3/16 9:23 PM, Tom Lane wrote:
Another potential problem for regnamespace is that it doesn't allow an
entry for the catalog. I'm not sure what the spec says about that, but
every other function allows dbname.schema.blah (dbname == catalog).

Meh, these types conform to no spec, so we can make them do what we
like.  I see about zero reason to allow a catalog name, it would mostly
just confuse people.

Ok. Not like CREATE SCHEMA allows that anyway.

I started working on a fix, but it's currently blowing up in bootstrap
and I haven't been able to figure out why yet:
running bootstrap script ... FATAL:  improper qualified name (too many
dotted names): oid_ops

Recommendation: don't muck with DeconstructQualifiedName.  That is called
in too many places and we are *not* touching any such API twenty-four
hours before release wrap.

Yeah, looks like that's what was blowing up.

There's no real advantage to that anyway, compared with just doing
stringToQualifiedNameList and then complaining if its list_length isn't 1.

What I went with. Now to figure out why this is happening...

  SELECT regnamespace('pg_catalog');
! ERROR:  schema "Y" does not exist
! LINE 1: SELECT regnamespace('pg_catalog');
!
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 59e5dc8..339bfe7 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -1569,6 +1569,7 @@ Datum
 regrolein(PG_FUNCTION_ARGS)
 {
        char       *role_name_or_oid = PG_GETARG_CSTRING(0);
+       List       *names;
        Oid                     result;
 
        /* '-' ? */
@@ -1586,7 +1587,15 @@ 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_SYNTAX_ERROR),
+                       errmsg("improper qualified name (too many dotted 
names): %s",
+                                  NameListToString(names))));
+
+       result = get_role_oid(strVal(linitial(names)), false);
 
        PG_RETURN_OID(result);
 }
@@ -1668,7 +1677,9 @@ Datum
 regnamespacein(PG_FUNCTION_ARGS)
 {
        char       *nsp_name_or_oid = PG_GETARG_CSTRING(0);
+       char       *nsp_name;
        Oid                     result = InvalidOid;
+       List       *names;
 
        /* '-' ? */
        if (strcmp(nsp_name_or_oid, "-") == 0)
@@ -1685,7 +1696,15 @@ 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_SYNTAX_ERROR),
+                       errmsg("improper qualified name (too many dotted 
names): %s",
+                                  NameListToString(names))));
+
+       result = get_namespace_oid(nsp_name, false);
 
        PG_RETURN_OID(result);
 }
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to