default namespace (schema) confusion - Mailing list pgsql-hackers

From Carl Anderson
Subject default namespace (schema) confusion
Date
Msg-id 20021018014238.GA28480@vadose
Whole thread Raw
Responses Re: default namespace (schema) confusion
List pgsql-hackers
I have been looking forward to schemas (namespaces) for sometime.

I had not been able to decipher the schema symantics necessary for a
default schema, until I hacked the source a bit.

Now I know that the rules to get a default schema usingdb_user_namespace = truesearch_path = '$user,public'
in postgresql.conf


the user logs in aspsql testdb  testuser

but the userid is reallytestuser@testdb

if a schema named "testuser@testdb" exists
the user gets it as a default schema
otherwise the default schema is public;

and if the user is a global user
the login ispsql testdb globuser@
and the required schema is "globuser"

this use of "@" in the default schema is a bit counter intuitive


so I offer the following patch against CVS

it tries the userid as found in pg_user,
then strips off the @db stuff if possible

--- src/backend/catalog/namespace.c    Thu Oct 17 21:23:34 2002
+++ src/backend/catalog/namespace_2.c    Thu Oct 17 21:21:52 2002
@@ -1386,8 +1386,10 @@             if (HeapTupleIsValid(tuple))             {                 char       *uname;
+                char       *uname_local;                  uname = NameStr(((Form_pg_shadow) 
GETSTRUCT(tuple))->usename);                 namespaceId = 
GetSysCacheOid(NAMESPACENAME,                                              
CStringGetDatum(uname),                                              
0, 0, 0);
@@ -1396,7 +1398,25 @@                     !intMember(namespaceId, 
oidlist) &&                      
pg_namespace_aclcheck(namespaceId, userId,                                           
ACL_USAGE) == ACLCHECK_OK)
+                {                     oidlist = lappendi(oidlist, 
namespaceId);
+                }
+                else
+                {     
+                    uname_local = (char *) 
malloc(strlen(uname)); +                    strcpy 
(uname_local,uname);
+                    uname_local = 
strtok(uname_local,"@");
+                    namespaceId = 
GetSysCacheOid(NAMESPACENAME,
+                                 
CStringGetDatum(uname_local),
+                                     
0, 0, 0);
+                    if (OidIsValid(namespaceId) &&
+                        !intMember(namespaceId, 
oidlist) &&
+                         
pg_namespace_aclcheck(namespaceId, userId,
+                                          
ACL_USAGE) == ACLCHECK_OK)
+                        oidlist = 
lappendi(oidlist, namespaceId);
+                    free(uname_local);
+                }
+             }         }         else






pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Current CVS has strange parser for float type
Next
From: Tom Lane
Date:
Subject: Re: default namespace (schema) confusion