Hi,
attached is a patch that adds display of the groups a user belongs to to
\du and a \dg command to psql. It's against 7.4beta5.
--
Markus Bertheau [EMAIL PROTECTED]
diff -ru postgresql-7.4beta5.orig/src/bin/psql/command.c postgresql-7.4beta5/src/bin/psql/command.c
--- postgresql-7.4beta5.orig/src/bin/psql/command.c 2003-10-11 20:04:26.0 +0200
+++ postgresql-7.4beta5/src/bin/psql/command.c 2003-11-02 19:31:27.0 +0100
@@ -363,6 +363,9 @@
case 'f':
success = describeFunctions(pattern, show_verbose);
break;
+ case 'g':
+success = describeGroups(pattern);
+break;
case 'l':
success = do_lo_list();
break;
diff -ru postgresql-7.4beta5.orig/src/bin/psql/describe.c postgresql-7.4beta5/src/bin/psql/describe.c
--- postgresql-7.4beta5.orig/src/bin/psql/describe.c 2003-10-17 02:57:04.0 +0200
+++ postgresql-7.4beta5/src/bin/psql/describe.c 2003-11-02 19:38:31.0 +0100
@@ -1272,12 +1272,13 @@
WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n
WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n
ELSE CAST('' AS pg_catalog.text)\n
- END AS \%s\\n
+ END AS \%s\,\n
+ ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as \%s\\n
FROM pg_catalog.pg_user u\n,
_(User name), _(User ID),
_(superuser, create database),
_(superuser), _(create database),
- _(Attributes));
+ _(Attributes), _(Groups));
processNamePattern(buf, pattern, false, false,
NULL, u.usename, NULL, NULL);
@@ -1300,6 +1301,46 @@
/*
+ * \dg
+ *
+ * Describes groups.
+ */
+bool
+describeGroups(const char *pattern)
+{
+ PQExpBufferData buf;
+ PGresult *res;
+ printQueryOpt myopt = pset.popt;
+
+ initPQExpBuffer(buf);
+
+ printfPQExpBuffer(buf,
+ SELECT g.groname AS \%s\,\n
+ g.grosysid AS \%s\\n
+ FROM pg_catalog.pg_group g\n,
+ _(Group name), _(Group ID));
+
+ processNamePattern(buf, pattern, false, false,
+ NULL, g.groname, NULL, NULL);
+
+ appendPQExpBuffer(buf, ORDER BY 1;);
+
+ res = PSQLexec(buf.data, false);
+ termPQExpBuffer(buf);
+ if (!res)
+ return false;
+
+ myopt.nullPrint = NULL;
+ myopt.title = _(List of database groups);
+
+ printQuery(res, myopt, pset.queryFout);
+
+ PQclear(res);
+ return true;
+}
+
+
+/*
* listTables()
*
* handler for \d, \dt, etc.
diff -ru postgresql-7.4beta5.orig/src/bin/psql/describe.h postgresql-7.4beta5/src/bin/psql/describe.h
--- postgresql-7.4beta5.orig/src/bin/psql/describe.h 2003-08-05 01:59:40.0 +0200
+++ postgresql-7.4beta5/src/bin/psql/describe.h 2003-11-02 19:31:27.0 +0100
@@ -25,6 +25,9 @@
/* \du */
bool describeUsers(const char *pattern);
+/* \dg */
+bool describeGroups(const char *pattern);
+
/* \z (or \dp) */
bool permissionsList(const char *pattern);
diff -ru postgresql-7.4beta5.orig/src/bin/psql/help.c postgresql-7.4beta5/src/bin/psql/help.c
--- postgresql-7.4beta5.orig/src/bin/psql/help.c 2003-10-02 08:39:31.0 +0200
+++ postgresql-7.4beta5/src/bin/psql/help.c 2003-11-02 19:31:27.0 +0100
@@ -216,6 +216,7 @@
fprintf(output, _( \\dd [PATTERN] show comment for object\n));
fprintf(output, _( \\dD [PATTERN] list domains\n));
fprintf(output, _( \\df [PATTERN] list functions (add \+\ for more detail)\n));
+ fprintf(output, _( \\dg [PATTERN] list groups\n));
fprintf(output, _( \\dn [PATTERN] list schemas\n));
fprintf(output, _( \\do [NAME] list operators\n));
fprintf(output, _( \\dllist large objects, same as \\lo_list\n));
diff -ru postgresql-7.4beta5.orig/src/bin/psql/tab-complete.c postgresql-7.4beta5/src/bin/psql/tab-complete.c
--- postgresql-7.4beta5.orig/src/bin/psql/tab-complete.c 2003-10-17 13:52:06.0 +0200
+++ postgresql-7.4beta5/src/bin/psql/tab-complete.c 2003-11-02 19:32:40.0 +0100
@@ -614,7 +614,7 @@
static char *backslash_commands[] = {
\\a, \\connect, \\C, \\cd, \\copy, \\copyright,
- \\d, \\da, \\dc, \\dC, \\dd, \\dD, \\df, \\di,
+ \\d, \\da, \\dc, \\dC, \\dd, \\dD, \\df, \\dg, \\di,
\\dl, \\dn, \\do, \\dp, \\ds, \\dS, \\dt, \\dT,
\\dv, \\du,
\\e, \\echo, \\encoding,
---(end of broadcast)---
TIP 6: Have you searched our list archives?
http://archives.postgresql.org