Commit 71928e7b authored by Bruce Momjian's avatar Bruce Momjian

Make psql \d and \dt consistent for system tables, i.e prevent \d from

showing system tables, make \dS pattern show system table details, and
have \dtS show system and _user_ tables, to be consistent with other \d*
commands.
parent 2384287f
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2009, PostgreSQL Global Development Group * Copyright (c) 2000-2009, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.201 2009/01/06 21:10:30 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.202 2009/01/20 02:13:42 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "command.h" #include "command.h"
...@@ -334,14 +334,15 @@ exec_command(const char *cmd, ...@@ -334,14 +334,15 @@ exec_command(const char *cmd,
OT_NORMAL, NULL, true); OT_NORMAL, NULL, true);
show_verbose = strchr(cmd, '+') ? true : false; show_verbose = strchr(cmd, '+') ? true : false;
show_system = strchr(cmd, 'S') ? true: false; show_system = strchr(cmd, 'S') ? true : false;
switch (cmd[1]) switch (cmd[1])
{ {
case '\0': case '\0':
case '+': case '+':
case 'S':
if (pattern) if (pattern)
success = describeTableDetails(pattern, show_verbose); success = describeTableDetails(pattern, show_verbose, show_system);
else else
/* standard listing of interesting things */ /* standard listing of interesting things */
success = listTables("tvs", NULL, show_verbose, show_system); success = listTables("tvs", NULL, show_verbose, show_system);
...@@ -390,7 +391,6 @@ exec_command(const char *cmd, ...@@ -390,7 +391,6 @@ exec_command(const char *cmd,
case 'v': case 'v':
case 'i': case 'i':
case 's': case 's':
case 'S':
success = listTables(&cmd[1], pattern, show_verbose, show_system); success = listTables(&cmd[1], pattern, show_verbose, show_system);
break; break;
case 'u': case 'u':
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* Copyright (c) 2000-2009, PostgreSQL Global Development Group * Copyright (c) 2000-2009, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.196 2009/01/19 18:44:32 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.197 2009/01/20 02:13:42 momjian Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -782,7 +782,7 @@ objectDescription(const char *pattern, bool showSystem) ...@@ -782,7 +782,7 @@ objectDescription(const char *pattern, bool showSystem)
* verbose: if true, this is \d+ * verbose: if true, this is \d+
*/ */
bool bool
describeTableDetails(const char *pattern, bool verbose) describeTableDetails(const char *pattern, bool verbose, bool showSystem)
{ {
PQExpBufferData buf; PQExpBufferData buf;
PGresult *res; PGresult *res;
...@@ -797,7 +797,10 @@ describeTableDetails(const char *pattern, bool verbose) ...@@ -797,7 +797,10 @@ describeTableDetails(const char *pattern, bool verbose)
"FROM pg_catalog.pg_class c\n" "FROM pg_catalog.pg_class c\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"); " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
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", "c.relname", NULL, "n.nspname", "c.relname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)"); "pg_catalog.pg_table_is_visible(c.oid)");
...@@ -1961,20 +1964,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys ...@@ -1961,20 +1964,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
appendPQExpBuffer(&buf, "'i',"); appendPQExpBuffer(&buf, "'i',");
if (showSeq) if (showSeq)
appendPQExpBuffer(&buf, "'S',"); appendPQExpBuffer(&buf, "'S',");
if (showSystem && showTables) if (showSystem)
appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <= 8.1.X */ appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <= 8.1.X */
appendPQExpBuffer(&buf, "''"); /* dummy */ appendPQExpBuffer(&buf, "''"); /* dummy */
appendPQExpBuffer(&buf, ")\n"); appendPQExpBuffer(&buf, ")\n");
/* if (!showSystem)
* If showSystem is specified, show only system objects (those in /* Exclude system and pg_toast objects, but show temp tables */
* pg_catalog). Otherwise, suppress system objects, including those in
* pg_catalog and pg_toast. (We don't want to hide temp tables though.)
*/
if (showSystem)
appendPQExpBuffer(&buf,
" AND n.nspname = 'pg_catalog'\n");
else
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
" AND n.nspname <> 'pg_catalog'\n" " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname !~ '^pg_toast'\n"); " AND n.nspname !~ '^pg_toast'\n");
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2009, PostgreSQL Global Development Group * Copyright (c) 2000-2009, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.38 2009/01/06 21:10:30 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.39 2009/01/20 02:13:42 momjian Exp $
*/ */
#ifndef DESCRIBE_H #ifndef DESCRIBE_H
#define DESCRIBE_H #define DESCRIBE_H
...@@ -34,7 +34,7 @@ extern bool permissionsList(const char *pattern); ...@@ -34,7 +34,7 @@ extern bool permissionsList(const char *pattern);
extern bool objectDescription(const char *pattern, bool showSystem); extern bool objectDescription(const char *pattern, bool showSystem);
/* \d foo */ /* \d foo */
extern bool describeTableDetails(const char *pattern, bool verbose); extern bool describeTableDetails(const char *pattern, bool verbose, bool showSystem);
/* \dF */ /* \dF */
extern bool listTSConfigs(const char *pattern, bool verbose); extern bool listTSConfigs(const char *pattern, bool verbose);
......
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