From: Tom Lane Date: Sun, 7 Nov 2010 01:41:14 +0000 (-0400) Subject: Implement an "S" option for psql's \dn command. X-Git-Tag: REL9_1_ALPHA3~205 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e43fb604d6db229d70d3101aa53348cc16a5473a;p=postgresql 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. --- diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index eb716cf6f0..d44fc56b37 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1232,16 +1232,17 @@ testdb=> - \dn[+] [ pattern ] + \dn[S+] [ pattern ] Lists schemas (namespaces). If pattern is specified, only schemas whose names match the pattern are listed. - Non-local temporary schemas are suppressed. If + - 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 S modifier to include system objects. + If + is appended to the command name, each object + is listed with its associated permissions and description, if any. diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index fe37be66f2..c1edf44a60 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -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); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index b705cb29dd..c4370a1dd3 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -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); diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index ddf4aac482..6a6abdba47 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -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);