]> granicus.if.org Git - postgresql/commitdiff
Implement an "S" option for psql's \dn command.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Nov 2010 01:41:14 +0000 (21:41 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 7 Nov 2010 01:41:14 +0000 (21:41 -0400)
\dn without "S" now hides all pg_XXX schemas as well as information_schema.
Thus, in a bare database you'll only see "public".  ("public" is considered
a user schema, not a system schema, mainly because it's droppable.)
Per discussion back in late September.

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h

index eb716cf6f09686fa0dba9283b40ec8db77b0f1bb..d44fc56b37e1c11cfcc659a27812cc35b7a9a160 100644 (file)
@@ -1232,16 +1232,17 @@ testdb=&gt;
 
 
       <varlistentry>
-        <term><literal>\dn[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+        <term><literal>\dn[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
 
         <listitem>
         <para>
         Lists schemas (namespaces). If <replaceable
         class="parameter">pattern</replaceable>
         is specified, only schemas whose names match the pattern are listed.
-        Non-local temporary schemas are suppressed.  If <literal>+</literal>
-        is appended to the command name, each object is listed with its associated
-        permissions and description, if any.
+        By default, only user-created objects are shown; supply a
+        pattern or the <literal>S</literal> modifier to include system objects.
+        If <literal>+</literal> is appended to the command name, each object
+        is listed with its associated permissions and description, if any.
         </para>
         </listitem>
       </varlistentry>
index fe37be66f2a854c8d1921327cee53754a568eb17..c1edf44a6071d63c3bfb50515cf2f0b5b2cc04c2 100644 (file)
@@ -417,7 +417,7 @@ exec_command(const char *cmd,
                                success = do_lo_list();
                                break;
                        case 'n':
-                               success = listSchemas(pattern, show_verbose);
+                               success = listSchemas(pattern, show_verbose, show_system);
                                break;
                        case 'o':
                                success = describeOperators(pattern, show_system);
index b705cb29dd419b207a365ae61801f8a6512da253..c4370a1dd39c8133cf509edad1f46a9c0b0fc9a6 100644 (file)
@@ -2697,7 +2697,7 @@ listCasts(const char *pattern)
  * Describes schemas (namespaces)
  */
 bool
-listSchemas(const char *pattern, bool verbose)
+listSchemas(const char *pattern, bool verbose, bool showSystem)
 {
        PQExpBufferData buf;
        PGresult   *res;
@@ -2720,11 +2720,14 @@ listSchemas(const char *pattern, bool verbose)
        }
 
        appendPQExpBuffer(&buf,
-                                         "\nFROM pg_catalog.pg_namespace n\n"
-                                         "WHERE        (n.nspname !~ '^pg_temp_' OR\n"
-                  "             n.nspname = (pg_catalog.current_schemas(true))[1])\n");                /* temp schema is first */
+                                         "\nFROM pg_catalog.pg_namespace n\n");
 
-       processSQLNamePattern(pset.db, &buf, pattern, true, false,
+       if (!showSystem && !pattern)
+               appendPQExpBuffer(&buf,
+                                                 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
+
+       processSQLNamePattern(pset.db, &buf, pattern,
+                                                 !showSystem && !pattern, false,
                                                  NULL, "n.nspname", NULL,
                                                  NULL);
 
index ddf4aac482be7336bcb26129611183bcc448af36..6a6abdba471fd5e613b799b2f6c28834ca9580aa 100644 (file)
@@ -70,7 +70,7 @@ extern bool listConversions(const char *pattern, bool showSystem);
 extern bool listCasts(const char *pattern);
 
 /* \dn */
-extern bool listSchemas(const char *pattern, bool verbose);
+extern bool listSchemas(const char *pattern, bool verbose, bool showSystem);
 
 /* \dew */
 extern bool listForeignDataWrappers(const char *pattern, bool verbose);