Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e43fb60

Browse files
committed
Implement an "S" option for psql's \dn command.
\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.
1 parent d7a2ce4 commit e43fb60

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -1232,16 +1232,17 @@ testdb=>
12321232

12331233

12341234
<varlistentry>
1235-
<term><literal>\dn[+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
1235+
<term><literal>\dn[S+] [ <link linkend="APP-PSQL-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
12361236

12371237
<listitem>
12381238
<para>
12391239
Lists schemas (namespaces). If <replaceable
12401240
class="parameter">pattern</replaceable>
12411241
is specified, only schemas whose names match the pattern are listed.
1242-
Non-local temporary schemas are suppressed. If <literal>+</literal>
1243-
is appended to the command name, each object is listed with its associated
1244-
permissions and description, if any.
1242+
By default, only user-created objects are shown; supply a
1243+
pattern or the <literal>S</literal> modifier to include system objects.
1244+
If <literal>+</literal> is appended to the command name, each object
1245+
is listed with its associated permissions and description, if any.
12451246
</para>
12461247
</listitem>
12471248
</varlistentry>

src/bin/psql/command.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ exec_command(const char *cmd,
417417
success = do_lo_list();
418418
break;
419419
case 'n':
420-
success = listSchemas(pattern, show_verbose);
420+
success = listSchemas(pattern, show_verbose, show_system);
421421
break;
422422
case 'o':
423423
success = describeOperators(pattern, show_system);

src/bin/psql/describe.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ listCasts(const char *pattern)
26972697
* Describes schemas (namespaces)
26982698
*/
26992699
bool
2700-
listSchemas(const char *pattern, bool verbose)
2700+
listSchemas(const char *pattern, bool verbose, bool showSystem)
27012701
{
27022702
PQExpBufferData buf;
27032703
PGresult *res;
@@ -2720,11 +2720,14 @@ listSchemas(const char *pattern, bool verbose)
27202720
}
27212721

27222722
appendPQExpBuffer(&buf,
2723-
"\nFROM pg_catalog.pg_namespace n\n"
2724-
"WHERE (n.nspname !~ '^pg_temp_' OR\n"
2725-
" n.nspname = (pg_catalog.current_schemas(true))[1])\n"); /* temp schema is first */
2723+
"\nFROM pg_catalog.pg_namespace n\n");
27262724

2727-
processSQLNamePattern(pset.db, &buf, pattern, true, false,
2725+
if (!showSystem && !pattern)
2726+
appendPQExpBuffer(&buf,
2727+
"WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
2728+
2729+
processSQLNamePattern(pset.db, &buf, pattern,
2730+
!showSystem && !pattern, false,
27282731
NULL, "n.nspname", NULL,
27292732
NULL);
27302733

src/bin/psql/describe.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern bool listConversions(const char *pattern, bool showSystem);
7070
extern bool listCasts(const char *pattern);
7171

7272
/* \dn */
73-
extern bool listSchemas(const char *pattern, bool verbose);
73+
extern bool listSchemas(const char *pattern, bool verbose, bool showSystem);
7474

7575
/* \dew */
7676
extern bool listForeignDataWrappers(const char *pattern, bool verbose);

0 commit comments

Comments
 (0)