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@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 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





---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply via email to