Skip to content

Commit 84ccf72

Browse files
committed
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).
1 parent f60d176 commit 84ccf72

File tree

5 files changed

+200
-245
lines changed

5 files changed

+200
-245
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.148 2005/07/18 20:57:52 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.149 2005/08/14 18:49:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -963,9 +963,10 @@ testdb=&gt;
963963
<term><literal>\dg [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
964964
<listitem>
965965
<para>
966-
Lists all database groups. If <replaceable
966+
Lists all database roles. If <replaceable
967967
class="parameter">pattern</replaceable> is specified, only
968-
those groups whose names match the pattern are listed.
968+
those roles whose names match the pattern are listed.
969+
(This command is now effectively the same as <literal>\du</>.)
969970
</para>
970971
</listitem>
971972
</varlistentry>
@@ -1073,7 +1074,7 @@ testdb=&gt;
10731074
<term><literal>\du [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
10741075
<listitem>
10751076
<para>
1076-
Lists all database users or only those that match <replaceable
1077+
Lists all database roles, or only those that match <replaceable
10771078
class="parameter">pattern</replaceable>.
10781079
</para>
10791080
</listitem>

src/bin/psql/command.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.151 2005/07/25 17:17:41 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.152 2005/08/14 18:49:30 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -338,7 +338,8 @@ exec_command(const char *cmd,
338338
success = describeFunctions(pattern, show_verbose);
339339
break;
340340
case 'g':
341-
success = describeGroups(pattern);
341+
/* no longer distinct from \du */
342+
success = describeRoles(pattern);
342343
break;
343344
case 'l':
344345
success = do_lo_list();
@@ -363,7 +364,7 @@ exec_command(const char *cmd,
363364
success = listTables(&cmd[1], pattern, show_verbose);
364365
break;
365366
case 'u':
366-
success = describeUsers(pattern);
367+
success = describeRoles(pattern);
367368
break;
368369

369370
default:

src/bin/psql/describe.c

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.122 2005/07/18 19:09:09 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.123 2005/08/14 18:49:30 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "describe.h"
@@ -1377,12 +1377,12 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers,
13771377
}
13781378

13791379
/*
1380-
* \du
1380+
* \du or \dg
13811381
*
1382-
* Describes users. Any schema portion of the pattern is ignored.
1382+
* Describes roles. Any schema portion of the pattern is ignored.
13831383
*/
13841384
bool
1385-
describeUsers(const char *pattern)
1385+
describeRoles(const char *pattern)
13861386
{
13871387
PQExpBufferData buf;
13881388
PGresult *res;
@@ -1391,62 +1391,24 @@ describeUsers(const char *pattern)
13911391
initPQExpBuffer(&buf);
13921392

13931393
printfPQExpBuffer(&buf,
1394-
"SELECT u.usename AS \"%s\",\n"
1395-
" u.usesysid AS \"%s\",\n"
1396-
" CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
1397-
" WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n"
1398-
" WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
1399-
" ELSE CAST('' AS pg_catalog.text)\n"
1400-
" END AS \"%s\",\n"
1401-
" ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as \"%s\"\n"
1402-
"FROM pg_catalog.pg_user u\n",
1403-
_("User name"), _("User ID"),
1404-
_("superuser, create database"),
1405-
_("superuser"), _("create database"),
1406-
_("Attributes"), _("Groups"));
1407-
1408-
processNamePattern(&buf, pattern, false, false,
1409-
NULL, "u.usename", NULL, NULL);
1410-
1411-
appendPQExpBuffer(&buf, "ORDER BY 1;");
1412-
1413-
res = PSQLexec(buf.data, false);
1414-
termPQExpBuffer(&buf);
1415-
if (!res)
1416-
return false;
1417-
1418-
myopt.nullPrint = NULL;
1419-
myopt.title = _("List of users");
1420-
1421-
printQuery(res, &myopt, pset.queryFout, pset.logfile);
1422-
1423-
PQclear(res);
1424-
return true;
1425-
}
1426-
1427-
1428-
/*
1429-
* \dg
1430-
*
1431-
* Describes groups.
1432-
*/
1433-
bool
1434-
describeGroups(const char *pattern)
1435-
{
1436-
PQExpBufferData buf;
1437-
PGresult *res;
1438-
printQueryOpt myopt = pset.popt;
1439-
1440-
initPQExpBuffer(&buf);
1441-
1442-
printfPQExpBuffer(&buf,
1443-
"SELECT g.groname AS \"%s\",\n"
1444-
" g.grosysid AS \"%s\"\n"
1445-
"FROM pg_catalog.pg_group g\n",
1446-
_("Group name"), _("Group ID"));
1394+
"SELECT r.rolname AS \"%s\",\n"
1395+
" CASE WHEN r.rolsuper THEN '%s' ELSE '%s' END AS \"%s\",\n"
1396+
" CASE WHEN r.rolcreaterole THEN '%s' ELSE '%s' END AS \"%s\",\n"
1397+
" CASE WHEN r.rolcreatedb THEN '%s' ELSE '%s' END AS \"%s\",\n"
1398+
" CASE WHEN r.rolconnlimit < 0 THEN CAST('%s' AS pg_catalog.text)\n"
1399+
" ELSE CAST(r.rolconnlimit AS pg_catalog.text)\n"
1400+
" END AS \"%s\", \n"
1401+
" 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"
1402+
"FROM pg_catalog.pg_roles r\n",
1403+
_("Role name"),
1404+
_("yes"),_("no"),_("Superuser"),
1405+
_("yes"),_("no"),_("Create role"),
1406+
_("yes"),_("no"),_("Create DB"),
1407+
_("no limit"),_("Connections"),
1408+
_("Member of"));
14471409

14481410
processNamePattern(&buf, pattern, false, false,
1449-
NULL, "g.groname", NULL, NULL);
1411+
NULL, "r.rolname", NULL, NULL);
14501412

14511413
appendPQExpBuffer(&buf, "ORDER BY 1;");
14521414

@@ -1456,7 +1418,7 @@ describeGroups(const char *pattern)
14561418
return false;
14571419

14581420
myopt.nullPrint = NULL;
1459-
myopt.title = _("List of groups");
1421+
myopt.title = _("List of roles");
14601422

14611423
printQuery(res, &myopt, pset.queryFout, pset.logfile);
14621424

src/bin/psql/describe.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,57 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.28 2005/01/01 05:43:08 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.29 2005/08/14 18:49:30 tgl Exp $
77
*/
88
#ifndef DESCRIBE_H
99
#define DESCRIBE_H
1010

1111
#include "settings.h"
1212

1313
/* \da */
14-
bool describeAggregates(const char *pattern, bool verbose);
14+
extern bool describeAggregates(const char *pattern, bool verbose);
1515

1616
/* \db */
17-
bool describeTablespaces(const char *pattern, bool verbose);
17+
extern bool describeTablespaces(const char *pattern, bool verbose);
1818

1919
/* \df */
20-
bool describeFunctions(const char *pattern, bool verbose);
20+
extern bool describeFunctions(const char *pattern, bool verbose);
2121

2222
/* \dT */
23-
bool describeTypes(const char *pattern, bool verbose);
23+
extern bool describeTypes(const char *pattern, bool verbose);
2424

2525
/* \do */
26-
bool describeOperators(const char *pattern);
26+
extern bool describeOperators(const char *pattern);
2727

28-
/* \du */
29-
bool describeUsers(const char *pattern);
30-
31-
/* \dg */
32-
bool describeGroups(const char *pattern);
28+
/* \du, \dg */
29+
extern bool describeRoles(const char *pattern);
3330

3431
/* \z (or \dp) */
35-
bool permissionsList(const char *pattern);
32+
extern bool permissionsList(const char *pattern);
3633

3734
/* \dd */
38-
bool objectDescription(const char *pattern);
35+
extern bool objectDescription(const char *pattern);
3936

4037
/* \d foo */
41-
bool describeTableDetails(const char *pattern, bool verbose);
38+
extern bool describeTableDetails(const char *pattern, bool verbose);
4239

4340
/* \l */
44-
bool listAllDbs(bool verbose);
41+
extern bool listAllDbs(bool verbose);
4542

4643
/* \dt, \di, \ds, \dS, etc. */
47-
bool listTables(const char *tabtypes, const char *pattern, bool verbose);
44+
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose);
4845

4946
/* \dD */
50-
bool listDomains(const char *pattern);
47+
extern bool listDomains(const char *pattern);
5148

5249
/* \dc */
53-
bool listConversions(const char *pattern);
50+
extern bool listConversions(const char *pattern);
5451

5552
/* \dC */
56-
bool listCasts(const char *pattern);
53+
extern bool listCasts(const char *pattern);
5754

5855
/* \dn */
59-
bool listSchemas(const char *pattern, bool verbose);
56+
extern bool listSchemas(const char *pattern, bool verbose);
6057

6158

6259
#endif /* DESCRIBE_H */

0 commit comments

Comments
 (0)