Make psql \d and \dt consistent for system tables, i.e prevent \d from
authorBruce Momjian <bruce@momjian.us>
Tue, 20 Jan 2009 02:13:42 +0000 (02:13 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 20 Jan 2009 02:13:42 +0000 (02:13 +0000)
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.

src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h

index f1bdb49dc8b6f18f111d398f3c42c6a27979f78d..6d6e187601a548df0f3257ede2bb718781e4d1c7 100644 (file)
@@ -334,14 +334,15 @@ exec_command(const char *cmd,
                                                                                 OT_NORMAL, NULL, true);
 
                show_verbose = strchr(cmd, '+') ? true : false;
-               show_system = strchr(cmd, 'S') ? true: false;
+               show_system = strchr(cmd, 'S') ? true : false;
 
                switch (cmd[1])
                {
                        case '\0':
                        case '+':
+                       case 'S':
                                if (pattern)
-                                       success = describeTableDetails(pattern, show_verbose);
+                                       success = describeTableDetails(pattern, show_verbose, show_system);
                                else
                                        /* standard listing of interesting things */
                                        success = listTables("tvs", NULL, show_verbose, show_system);
@@ -390,7 +391,6 @@ exec_command(const char *cmd,
                        case 'v':
                        case 'i':
                        case 's':
-                       case 'S':
                                success = listTables(&cmd[1], pattern, show_verbose, show_system);
                                break;
                        case 'u':
index 2ac1cd1586a3e849f13c25726136ea090b887831..75d46205999d4e582a7fbe0fa91a402500b914c4 100644 (file)
@@ -782,7 +782,7 @@ objectDescription(const char *pattern, bool showSystem)
  * verbose: if true, this is \d+
  */
 bool
-describeTableDetails(const char *pattern, bool verbose)
+describeTableDetails(const char *pattern, bool verbose, bool showSystem)
 {
        PQExpBufferData buf;
        PGresult   *res;
@@ -797,7 +797,10 @@ describeTableDetails(const char *pattern, bool verbose)
                                          "FROM pg_catalog.pg_class c\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,
                                                  "pg_catalog.pg_table_is_visible(c.oid)");
 
@@ -1961,20 +1964,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
                appendPQExpBuffer(&buf, "'i',");
        if (showSeq)
                appendPQExpBuffer(&buf, "'S',");
-       if (showSystem && showTables)
+       if (showSystem)
                appendPQExpBuffer(&buf, "'s',");        /* was RELKIND_SPECIAL in <= 8.1.X */
        appendPQExpBuffer(&buf, "''");          /* dummy */
        appendPQExpBuffer(&buf, ")\n");
 
-       /*
-        * If showSystem is specified, show only system objects (those in
-        * 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
+       if (!showSystem)
+               /* Exclude system and pg_toast objects, but show temp tables */
                appendPQExpBuffer(&buf,
                                                  "  AND n.nspname <> 'pg_catalog'\n"
                                                  "  AND n.nspname !~ '^pg_toast'\n");
index dfba6f64c4a8153dbf8ec82425a8f9b99f65dd27..57e5c7b3ac13d9dbaf82e961ad6ffafead91c1cb 100644 (file)
@@ -34,7 +34,7 @@ extern bool permissionsList(const char *pattern);
 extern bool objectDescription(const char *pattern, bool showSystem);
 
 /* \d foo */
-extern bool describeTableDetails(const char *pattern, bool verbose);
+extern bool describeTableDetails(const char *pattern, bool verbose, bool showSystem);
 
 /* \dF */
 extern bool listTSConfigs(const char *pattern, bool verbose);