This makes all the \dX commands (most importantly to most: \df) work

like \dt does, in that it requires a \dXS to see system items.

Greg Sabino Mullane
This commit is contained in:
Bruce Momjian 2009-01-06 21:10:30 +00:00
parent e825fac2a3
commit 9491c82f71
4 changed files with 111 additions and 62 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.200 2009/01/01 17:23:54 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.201 2009/01/06 21:10:30 momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
@ -327,13 +327,14 @@ exec_command(const char *cmd,
else if (cmd[0] == 'd')
{
char *pattern;
bool show_verbose;
bool show_verbose, show_system;
/* We don't do SQLID reduction on the pattern yet */
pattern = psql_scan_slash_option(scan_state,
OT_NORMAL, NULL, true);
show_verbose = strchr(cmd, '+') ? true : false;
show_system = strchr(cmd, 'S') ? true: false;
switch (cmd[1])
{
@ -343,28 +344,28 @@ exec_command(const char *cmd,
success = describeTableDetails(pattern, show_verbose);
else
/* standard listing of interesting things */
success = listTables("tvs", NULL, show_verbose);
success = listTables("tvs", NULL, show_verbose, show_system);
break;
case 'a':
success = describeAggregates(pattern, show_verbose);
success = describeAggregates(pattern, show_verbose, show_system);
break;
case 'b':
success = describeTablespaces(pattern, show_verbose);
break;
case 'c':
success = listConversions(pattern);
success = listConversions(pattern, show_system);
break;
case 'C':
success = listCasts(pattern);
break;
case 'd':
success = objectDescription(pattern);
success = objectDescription(pattern, show_system);
break;
case 'D':
success = listDomains(pattern);
success = listDomains(pattern, show_system);
break;
case 'f':
success = describeFunctions(pattern, show_verbose);
success = describeFunctions(pattern, show_verbose, show_system);
break;
case 'g':
/* no longer distinct from \du */
@ -377,20 +378,20 @@ exec_command(const char *cmd,
success = listSchemas(pattern, show_verbose);
break;
case 'o':
success = describeOperators(pattern);
success = describeOperators(pattern, show_system);
break;
case 'p':
success = permissionsList(pattern);
break;
case 'T':
success = describeTypes(pattern, show_verbose);
success = describeTypes(pattern, show_verbose, show_system);
break;
case 't':
case 'v':
case 'i':
case 's':
case 'S':
success = listTables(&cmd[1], pattern, show_verbose);
success = listTables(&cmd[1], pattern, show_verbose, show_system);
break;
case 'u':
success = describeRoles(pattern, show_verbose);

View File

@ -8,7 +8,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.193 2009/01/01 17:23:54 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.194 2009/01/06 21:10:30 momjian Exp $
*/
#include "postgres_fe.h"
@ -53,7 +53,7 @@ static void printACLColumn(PQExpBuffer buf, const char *colname);
* Takes an optional regexp to select particular aggregates
*/
bool
describeAggregates(const char *pattern, bool verbose)
describeAggregates(const char *pattern, bool verbose, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -76,7 +76,7 @@ describeAggregates(const char *pattern, bool verbose)
" ELSE\n"
" pg_catalog.array_to_string(ARRAY(\n"
" SELECT\n"
" pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
" pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
" FROM\n"
" pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
" ), ', ')\n"
@ -94,6 +94,9 @@ describeAggregates(const char *pattern, bool verbose)
"WHERE p.proisagg\n",
gettext_noop("Description"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)");
@ -182,7 +185,7 @@ describeTablespaces(const char *pattern, bool verbose)
* Takes an optional regexp to select particular functions
*/
bool
describeFunctions(const char *pattern, bool verbose)
describeFunctions(const char *pattern, bool verbose, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -278,6 +281,9 @@ describeFunctions(const char *pattern, bool verbose)
" AND p.proargtypes[0] IS DISTINCT FROM 'pg_catalog.cstring'::pg_catalog.regtype\n"
" AND NOT p.proisagg\n");
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)");
@ -306,7 +312,7 @@ describeFunctions(const char *pattern, bool verbose)
* describe types
*/
bool
describeTypes(const char *pattern, bool verbose)
describeTypes(const char *pattern, bool verbose, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -366,6 +372,9 @@ describeTypes(const char *pattern, bool verbose)
else
appendPQExpBuffer(&buf, " AND t.typname !~ '^_'\n");
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
/* Match name pattern against either internal or external name */
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "t.typname",
@ -393,7 +402,7 @@ describeTypes(const char *pattern, bool verbose)
/* \do
*/
bool
describeOperators(const char *pattern)
describeOperators(const char *pattern, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -418,7 +427,10 @@ describeOperators(const char *pattern)
gettext_noop("Result type"),
gettext_noop("Description"));
processSQLNamePattern(pset.db, &buf, pattern, false, true,
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, true,
"n.nspname", "o.oprname", NULL,
"pg_catalog.pg_operator_is_visible(o.oid)");
@ -580,7 +592,7 @@ permissionsList(const char *pattern)
* lists of things, there are other \d? commands.
*/
bool
objectDescription(const char *pattern)
objectDescription(const char *pattern, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -607,6 +619,10 @@ objectDescription(const char *pattern)
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
" WHERE p.proisagg\n",
gettext_noop("aggregate"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)");
@ -626,6 +642,10 @@ objectDescription(const char *pattern)
" OR p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype)\n"
" AND NOT p.proisagg\n",
gettext_noop("function"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)");
@ -640,7 +660,11 @@ objectDescription(const char *pattern)
" FROM pg_catalog.pg_operator o\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
gettext_noop("operator"));
processSQLNamePattern(pset.db, &buf, pattern, false, false,
if (!showSystem)
appendPQExpBuffer(&buf, " WHERE n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
"n.nspname", "o.oprname", NULL,
"pg_catalog.pg_operator_is_visible(o.oid)");
@ -654,7 +678,11 @@ objectDescription(const char *pattern)
" FROM pg_catalog.pg_type t\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
gettext_noop("data type"));
processSQLNamePattern(pset.db, &buf, pattern, false, false,
if (!showSystem)
appendPQExpBuffer(&buf, " WHERE n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
"n.nspname", "pg_catalog.format_type(t.oid, NULL)",
NULL,
"pg_catalog.pg_type_is_visible(t.oid)");
@ -675,6 +703,9 @@ objectDescription(const char *pattern)
gettext_noop("view"),
gettext_noop("index"),
gettext_noop("sequence"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "c.relname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
@ -691,6 +722,10 @@ objectDescription(const char *pattern)
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
" WHERE r.rulename != '_RETURN'\n",
gettext_noop("rule"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
/* XXX not sure what to do about visibility rule here? */
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "r.rulename", NULL,
@ -707,8 +742,11 @@ objectDescription(const char *pattern)
" JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
gettext_noop("trigger"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
/* XXX not sure what to do about visibility rule here? */
processSQLNamePattern(pset.db, &buf, pattern, false, false,
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
"n.nspname", "t.tgname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
@ -1856,13 +1894,12 @@ add_role_attribute(PQExpBuffer buf, const char *const str)
* (any order of the above is fine)
*/
bool
listTables(const char *tabtypes, const char *pattern, bool verbose)
listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
{
bool showTables = strchr(tabtypes, 't') != NULL;
bool showIndexes = strchr(tabtypes, 'i') != NULL;
bool showViews = strchr(tabtypes, 'v') != NULL;
bool showSeq = strchr(tabtypes, 's') != NULL;
bool showSystem = strchr(tabtypes, 'S') != NULL;
PQExpBufferData buf;
PGresult *res;
@ -1981,7 +2018,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
* Describes domains.
*/
bool
listDomains(const char *pattern)
listDomains(const char *pattern, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -2009,6 +2046,9 @@ listDomains(const char *pattern)
gettext_noop("Modifier"),
gettext_noop("Check"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "t.typname", NULL,
"pg_catalog.pg_type_is_visible(t.oid)");
@ -2036,7 +2076,7 @@ listDomains(const char *pattern)
* Describes conversions.
*/
bool
listConversions(const char *pattern)
listConversions(const char *pattern, bool showSystem)
{
PQExpBufferData buf;
PGresult *res;
@ -2061,6 +2101,9 @@ listConversions(const char *pattern)
gettext_noop("yes"), gettext_noop("no"),
gettext_noop("Default?"));
if (!showSystem)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "c.conname", NULL,
"pg_catalog.pg_conversion_is_visible(c.oid)");

View File

@ -3,26 +3,26 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.37 2009/01/01 17:23:55 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.38 2009/01/06 21:10:30 momjian Exp $
*/
#ifndef DESCRIBE_H
#define DESCRIBE_H
/* \da */
extern bool describeAggregates(const char *pattern, bool verbose);
extern bool describeAggregates(const char *pattern, bool verbose, bool showSystem);
/* \db */
extern bool describeTablespaces(const char *pattern, bool verbose);
/* \df */
extern bool describeFunctions(const char *pattern, bool verbose);
extern bool describeFunctions(const char *pattern, bool verbose, bool showSystem);
/* \dT */
extern bool describeTypes(const char *pattern, bool verbose);
extern bool describeTypes(const char *pattern, bool verbose, bool showSystem);
/* \do */
extern bool describeOperators(const char *pattern);
extern bool describeOperators(const char *pattern, bool showSystem);
/* \du, \dg */
extern bool describeRoles(const char *pattern, bool verbose);
@ -31,7 +31,7 @@ extern bool describeRoles(const char *pattern, bool verbose);
extern bool permissionsList(const char *pattern);
/* \dd */
extern bool objectDescription(const char *pattern);
extern bool objectDescription(const char *pattern, bool showSystem);
/* \d foo */
extern bool describeTableDetails(const char *pattern, bool verbose);
@ -52,13 +52,13 @@ extern bool listTSTemplates(const char *pattern, bool verbose);
extern bool listAllDbs(bool verbose);
/* \dt, \di, \ds, \dS, etc. */
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose);
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem);
/* \dD */
extern bool listDomains(const char *pattern);
extern bool listDomains(const char *pattern, bool showSystem);
/* \dc */
extern bool listConversions(const char *pattern);
extern bool listConversions(const char *pattern, bool showSystem);
/* \dC */
extern bool listCasts(const char *pattern);

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.133 2009/01/01 17:23:55 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.134 2009/01/06 21:10:30 momjian Exp $
*/
#include "postgres_fe.h"
@ -194,32 +194,37 @@ slashUsage(unsigned short int pager)
fprintf(output, "\n");
fprintf(output, _("Informational\n"));
fprintf(output, _(" \\d [NAME] describe table, index, sequence, or view\n"));
fprintf(output, _(" \\d{t|i|s|v|S} [PATTERN] (add \"+\" for more detail)\n"
" list tables/indexes/sequences/views/system tables\n"));
fprintf(output, _(" \\da [PATTERN] list aggregate functions\n"));
fprintf(output, _(" \\db [PATTERN] list tablespaces (add \"+\" for more detail)\n"));
fprintf(output, _(" \\dc [PATTERN] list conversions\n"));
fprintf(output, _(" \\dC [PATTERN] list casts\n"));
fprintf(output, _(" \\dd [PATTERN] show comment for object\n"));
fprintf(output, _(" \\dD [PATTERN] list domains\n"));
fprintf(output, _(" \\des [PATTERN] list foreign servers (add \"+\" for more detail)\n"));
fprintf(output, _(" \\deu [PATTERN] list user mappings (add \"+\" for more detail)\n"));
fprintf(output, _(" \\dew [PATTERN] list foreign-data wrappers (add \"+\" for more detail)\n"));
fprintf(output, _(" \\df [PATTERN] list functions (add \"+\" for more detail)\n"));
fprintf(output, _(" \\dF [PATTERN] list text search configurations (add \"+\" for more detail)\n"));
fprintf(output, _(" \\dFd [PATTERN] list text search dictionaries (add \"+\" for more detail)\n"));
fprintf(output, _(" \\dFt [PATTERN] list text search templates\n"));
fprintf(output, _(" \\dFp [PATTERN] list text search parsers (add \"+\" for more detail)\n"));
fprintf(output, _(" \\dg [PATTERN] list roles (groups)\n"));
fprintf(output, _(" \\dn [PATTERN] list schemas (add \"+\" for more detail)\n"));
fprintf(output, _(" \\do [NAME] list operators\n"));
fprintf(output, _(" \\dl list large objects, same as \\lo_list\n"));
fprintf(output, _(" \\dp [PATTERN] list table, view, and sequence access privileges\n"));
fprintf(output, _(" \\dT [PATTERN] list data types (add \"+\" for more detail)\n"));
fprintf(output, _(" \\du [PATTERN] list roles (users)\n"));
fprintf(output, _(" \\l list all databases (add \"+\" for more detail)\n"));
fprintf(output, _(" \\z [PATTERN] list table, view, and sequence access privileges (same as \\dp)\n"));
fprintf(output, _(" Modifiers: S = show system objects + = Additional detail\n"));
fprintf(output, _(" \\l[+] list all databases\n"));
fprintf(output, _(" \\d[S] list tables, views, and sequences\n"));
fprintf(output, _(" \\d[S] NAME describe table, view, sequence, or index\n"));
fprintf(output, _(" \\dt[S+] [PATTERN] list tables\n"));
fprintf(output, _(" \\dv[S+] [PATTERN] list views\n"));
fprintf(output, _(" \\ds[S+] [PATTERN] list sequences\n"));
fprintf(output, _(" \\di[S+] [PATTERN] list indexes\n"));
fprintf(output, _(" \\df[S+] [PATTERN] list functions\n"));
fprintf(output, _(" \\dT[S+] [PATTERN] list data types\n"));
fprintf(output, _(" \\dd[S] [PATTERN] list comments on objects\n"));
fprintf(output, _(" \\dD[S] [PATTERN] list domains\n"));
fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n"));
fprintf(output, _(" \\dew[+] [PATTERN] list foreign-data wrappers\n"));
fprintf(output, _(" \\do[S] [PATTERN] list operators\n"));
fprintf(output, _(" \\da[S] [PATTERN] list aggregate functions\n"));
fprintf(output, _(" \\dc[S] [PATTERN] list conversions\n"));
fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
fprintf(output, _(" \\dn[+] [PATTERN] list schemas\n"));
fprintf(output, _(" \\dC list casts\n"));
fprintf(output, _(" \\dd [PATTERN] show comment for object\n"));
fprintf(output, _(" \\dF[+] [PATTERN] list text search configurations\n"));
fprintf(output, _(" \\dFd[+] [PATTERN] list text search dictionaries\n"));
fprintf(output, _(" \\dFt [PATTERN] list text search templates\n"));
fprintf(output, _(" \\dFp[+] [PATTERN] list text search parsers\n"));
fprintf(output, _(" \\dg [PATTERN] list roles (groups)\n"));
fprintf(output, _(" \\dl list large objects, same as \\lo_list\n"));
fprintf(output, _(" \\du [PATTERN] list roles (users)\n"));
fprintf(output, _(" \\dp [PATTERN] list table, view, and sequence access privileges\n"));
fprintf(output, _(" \\z [PATTERN] same as \\dp\n"));
fprintf(output, "\n");
fprintf(output, _("Formatting\n"));