Commit 84ccf721 authored by Tom Lane's avatar Tom Lane

Fix up tab completion for ROLEs and add some more completion logic for

other stuff; change \du and \dg to be role-aware (Stefan Kaltenbrunner).
Also make tab completion fetch the list of GUC variables from pg_settings
instead of having a hard-wired copy of the list (Tom Lane).
parent f60d176a
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.148 2005/07/18 20:57:52 momjian Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.149 2005/08/14 18:49:29 tgl Exp $
PostgreSQL documentation
-->
......@@ -963,9 +963,10 @@ testdb=&gt;
<term><literal>\dg [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
<listitem>
<para>
Lists all database groups. If <replaceable
Lists all database roles. If <replaceable
class="parameter">pattern</replaceable> is specified, only
those groups whose names match the pattern are listed.
those roles whose names match the pattern are listed.
(This command is now effectively the same as <literal>\du</>.)
</para>
</listitem>
</varlistentry>
......@@ -1073,7 +1074,7 @@ testdb=&gt;
<term><literal>\du [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
<listitem>
<para>
Lists all database users or only those that match <replaceable
Lists all database roles, or only those that match <replaceable
class="parameter">pattern</replaceable>.
</para>
</listitem>
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.151 2005/07/25 17:17:41 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.152 2005/08/14 18:49:30 tgl Exp $
*/
#include "postgres_fe.h"
#include "command.h"
......@@ -338,7 +338,8 @@ exec_command(const char *cmd,
success = describeFunctions(pattern, show_verbose);
break;
case 'g':
success = describeGroups(pattern);
/* no longer distinct from \du */
success = describeRoles(pattern);
break;
case 'l':
success = do_lo_list();
......@@ -363,7 +364,7 @@ exec_command(const char *cmd,
success = listTables(&cmd[1], pattern, show_verbose);
break;
case 'u':
success = describeUsers(pattern);
success = describeRoles(pattern);
break;
default:
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.122 2005/07/18 19:09:09 tgl Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.123 2005/08/14 18:49:30 tgl Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
......@@ -1377,12 +1377,12 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers,
}
/*
* \du
* \du or \dg
*
* Describes users. Any schema portion of the pattern is ignored.
* Describes roles. Any schema portion of the pattern is ignored.
*/
bool
describeUsers(const char *pattern)
describeRoles(const char *pattern)
{
PQExpBufferData buf;
PGresult *res;
......@@ -1391,62 +1391,24 @@ describeUsers(const char *pattern)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
"SELECT u.usename AS \"%s\",\n"
" u.usesysid AS \"%s\",\n"
" CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
" 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"
" 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"), _("Groups"));
processNamePattern(&buf, pattern, false, false,
NULL, "u.usename", 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 users");
printQuery(res, &myopt, pset.queryFout, pset.logfile);
PQclear(res);
return true;
}
/*
* \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"));
"SELECT r.rolname AS \"%s\",\n"
" CASE WHEN r.rolsuper THEN '%s' ELSE '%s' END AS \"%s\",\n"
" CASE WHEN r.rolcreaterole THEN '%s' ELSE '%s' END AS \"%s\",\n"
" CASE WHEN r.rolcreatedb THEN '%s' ELSE '%s' END AS \"%s\",\n"
" CASE WHEN r.rolconnlimit < 0 THEN CAST('%s' AS pg_catalog.text)\n"
" ELSE CAST(r.rolconnlimit AS pg_catalog.text)\n"
" END AS \"%s\", \n"
" ARRAY(SELECT b.rolname FROM pg_catalog.pg_auth_members m JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid) WHERE m.member = r.oid) as \"%s\"\n"
"FROM pg_catalog.pg_roles r\n",
_("Role name"),
_("yes"),_("no"),_("Superuser"),
_("yes"),_("no"),_("Create role"),
_("yes"),_("no"),_("Create DB"),
_("no limit"),_("Connections"),
_("Member of"));
processNamePattern(&buf, pattern, false, false,
NULL, "g.groname", NULL, NULL);
NULL, "r.rolname", NULL, NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;");
......@@ -1456,7 +1418,7 @@ describeGroups(const char *pattern)
return false;
myopt.nullPrint = NULL;
myopt.title = _("List of groups");
myopt.title = _("List of roles");
printQuery(res, &myopt, pset.queryFout, pset.logfile);
......
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.28 2005/01/01 05:43:08 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.29 2005/08/14 18:49:30 tgl Exp $
*/
#ifndef DESCRIBE_H
#define DESCRIBE_H
......@@ -11,52 +11,49 @@
#include "settings.h"
/* \da */
bool describeAggregates(const char *pattern, bool verbose);
extern bool describeAggregates(const char *pattern, bool verbose);
/* \db */
bool describeTablespaces(const char *pattern, bool verbose);
extern bool describeTablespaces(const char *pattern, bool verbose);
/* \df */
bool describeFunctions(const char *pattern, bool verbose);
extern bool describeFunctions(const char *pattern, bool verbose);
/* \dT */
bool describeTypes(const char *pattern, bool verbose);
extern bool describeTypes(const char *pattern, bool verbose);
/* \do */
bool describeOperators(const char *pattern);
extern bool describeOperators(const char *pattern);
/* \du */
bool describeUsers(const char *pattern);
/* \dg */
bool describeGroups(const char *pattern);
/* \du, \dg */
extern bool describeRoles(const char *pattern);
/* \z (or \dp) */
bool permissionsList(const char *pattern);
extern bool permissionsList(const char *pattern);
/* \dd */
bool objectDescription(const char *pattern);
extern bool objectDescription(const char *pattern);
/* \d foo */
bool describeTableDetails(const char *pattern, bool verbose);
extern bool describeTableDetails(const char *pattern, bool verbose);
/* \l */
bool listAllDbs(bool verbose);
extern bool listAllDbs(bool verbose);
/* \dt, \di, \ds, \dS, etc. */
bool listTables(const char *tabtypes, const char *pattern, bool verbose);
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose);
/* \dD */
bool listDomains(const char *pattern);
extern bool listDomains(const char *pattern);
/* \dc */
bool listConversions(const char *pattern);
extern bool listConversions(const char *pattern);
/* \dC */
bool listCasts(const char *pattern);
extern bool listCasts(const char *pattern);
/* \dn */
bool listSchemas(const char *pattern, bool verbose);
extern bool listSchemas(const char *pattern, bool verbose);
#endif /* DESCRIBE_H */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment