default namespace (schema) confusion

From: Carl Anderson <candrsn(at)mindspring(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: default namespace (schema) confusion
Date: 2002-10-18 01:42:38
Message-ID: 20021018014238.GA28480@vadose
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 using
db_user_namespace = true
search_path = '$user,public'
in postgresql.conf

the user logs in as
psql testdb testuser

but the userid is really
testuser(at)testdb

if a schema named "testuser(at)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 is
psql 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-10-18 02:20:01 Re: default namespace (schema) confusion
Previous Message Bruce Momjian 2002-10-18 01:08:55 Re: Current CVS has strange parser for float type