mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
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 <twanger@bluetwanger.de>
This commit is contained in:
parent
5e2b99db95
commit
8bb60b6423
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.100 2003/11/29 19:51:39 pgsql Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.101 2003/12/01 22:21:54 momjian Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -904,6 +904,17 @@ testdb=>
|
||||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>\dg [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Lists all database groups or only those that match <replaceable
|
||||
class="parameter">pattern</replaceable>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>\distvS [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.107 2003/12/01 22:14:40 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.108 2003/12/01 22:21:54 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "command.h"
|
||||
@ -359,6 +359,9 @@ exec_command(const char *cmd,
|
||||
case 'f':
|
||||
success = describeFunctions(pattern, show_verbose);
|
||||
break;
|
||||
case 'g':
|
||||
success = describeGroups(pattern);
|
||||
break;
|
||||
case 'l':
|
||||
success = do_lo_list();
|
||||
break;
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.89 2003/12/01 22:11:06 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.90 2003/12/01 22:21:54 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "describe.h"
|
||||
@ -1276,12 +1276,13 @@ describeUsers(const char *pattern)
|
||||
" 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);
|
||||
@ -1303,6 +1304,46 @@ describeUsers(const char *pattern)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* \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()
|
||||
*
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.22 2003/11/29 19:52:06 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.23 2003/12/01 22:21:54 momjian Exp $
|
||||
*/
|
||||
#ifndef DESCRIBE_H
|
||||
#define DESCRIBE_H
|
||||
@ -25,6 +25,9 @@ bool describeOperators(const char *pattern);
|
||||
/* \du */
|
||||
bool describeUsers(const char *pattern);
|
||||
|
||||
/* \dg */
|
||||
bool describeGroups(const char *pattern);
|
||||
|
||||
/* \z (or \dp) */
|
||||
bool permissionsList(const char *pattern);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.82 2003/11/29 19:52:06 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.83 2003/12/01 22:21:54 momjian Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "common.h"
|
||||
@ -216,6 +216,7 @@ slashUsage(unsigned short int pager)
|
||||
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, _(" \\dl list large objects, same as \\lo_list\n"));
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.96 2003/12/01 22:14:40 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.97 2003/12/01 22:21:54 momjian Exp $
|
||||
*/
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
@ -576,7 +576,7 @@ psql_completion(char *text, int start, int end)
|
||||
|
||||
static const char * const 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",
|
||||
|
Loading…
Reference in New Issue
Block a user