Re: [PATCHES] psql: \dg and groups for \du

2003-12-01 Thread Bruce Momjian

Nice:

test= create group test;
CREATE GROUP
test= \dg
List of database groups
 Group name | Group ID 
+--
 test   |  100
(1 row)

test= alter group test add user postgres;
ALTER GROUP
test= \du
  List of database users
 User name | User ID | Attributes | Groups 
---+-++
 postgres  |   1 | superuser, create database | {test}
(1 row)

Patch applied, docs added, TODO updated.  Thanks.

---

Markus Bertheau wrote:
 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]

[ Attachment, skipping... ]

 
 ---(end of broadcast)---
 TIP 6: Have you searched our list archives?
 
http://archives.postgresql.org

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [PATCHES] psql: \dg and groups for \du

2003-12-01 Thread Peter Eisentraut
Note that it is planned to unify users and groups into a general role
entity, so this command is probably going to go away soon.


Bruce Momjian writes:

 Nice:

   test= create group test;
   CREATE GROUP
   test= \dg
   List of database groups
Group name | Group ID
   +--
test   |  100
   (1 row)

   test= alter group test add user postgres;
   ALTER GROUP
   test= \du
 List of database users
User name | User ID | Attributes | Groups
   ---+-++
postgres  |   1 | superuser, create database | {test}
   (1 row)

 Patch applied, docs added, TODO updated.  Thanks.

 ---

 Markus Bertheau wrote:
  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]

 [ Attachment, skipping... ]

 
  ---(end of broadcast)---
  TIP 6: Have you searched our list archives?
 
 http://archives.postgresql.org



-- 
Peter Eisentraut   [EMAIL PROTECTED]


---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


Re: [PATCHES] psql: \dg and groups for \du

2003-12-01 Thread Bruce Momjian
Peter Eisentraut wrote:
 Note that it is planned to unify users and groups into a general role
 entity, so this command is probably going to go away soon.

NP, at least the code is there for reuse.

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [PATCHES] psql: \dg and groups for \du

2003-11-11 Thread Bruce Momjian

I will write the psql.sgml changes.

Your patch has been added to the PostgreSQL unapplied patches list at:

http://momjian.postgresql.org/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

---


Markus Bertheau wrote:
 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]

[ Attachment, skipping... ]

 
 ---(end of broadcast)---
 TIP 6: Have you searched our list archives?
 
http://archives.postgresql.org

-- 
  Bruce Momjian|  http://candle.pha.pa.us
  [EMAIL PROTECTED]   |  (610) 359-1001
  +  If your life is a hard drive, |  13 Roberts Road
  +  Christ can be your backup.|  Newtown Square, Pennsylvania 19073

---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faqs/FAQ.html


[PATCHES] psql: \dg and groups for \du

2003-11-02 Thread Markus Bertheau
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