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

Commit 71928e7

Browse files
committed
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.
1 parent 2384287 commit 71928e7

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

src/bin/psql/command.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.201 2009/01/06 21:10:30 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.202 2009/01/20 02:13:42 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -334,14 +334,15 @@ exec_command(const char *cmd,
334334
OT_NORMAL, NULL, true);
335335

336336
show_verbose = strchr(cmd, '+') ? true : false;
337-
show_system = strchr(cmd, 'S') ? true: false;
337+
show_system = strchr(cmd, 'S') ? true : false;
338338

339339
switch (cmd[1])
340340
{
341341
case '\0':
342342
case '+':
343+
case 'S':
343344
if (pattern)
344-
success = describeTableDetails(pattern, show_verbose);
345+
success = describeTableDetails(pattern, show_verbose, show_system);
345346
else
346347
/* standard listing of interesting things */
347348
success = listTables("tvs", NULL, show_verbose, show_system);
@@ -390,7 +391,6 @@ exec_command(const char *cmd,
390391
case 'v':
391392
case 'i':
392393
case 's':
393-
case 'S':
394394
success = listTables(&cmd[1], pattern, show_verbose, show_system);
395395
break;
396396
case 'u':

src/bin/psql/describe.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
1010
*
11-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.196 2009/01/19 18:44:32 momjian Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.197 2009/01/20 02:13:42 momjian Exp $
1212
*/
1313
#include "postgres_fe.h"
1414

@@ -782,7 +782,7 @@ objectDescription(const char *pattern, bool showSystem)
782782
* verbose: if true, this is \d+
783783
*/
784784
bool
785-
describeTableDetails(const char *pattern, bool verbose)
785+
describeTableDetails(const char *pattern, bool verbose, bool showSystem)
786786
{
787787
PQExpBufferData buf;
788788
PGresult *res;
@@ -797,7 +797,10 @@ describeTableDetails(const char *pattern, bool verbose)
797797
"FROM pg_catalog.pg_class c\n"
798798
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
799799

800-
processSQLNamePattern(pset.db, &buf, pattern, false, false,
800+
if (!showSystem)
801+
appendPQExpBuffer(&buf, " WHERE n.nspname <> 'pg_catalog'\n");
802+
803+
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
801804
"n.nspname", "c.relname", NULL,
802805
"pg_catalog.pg_table_is_visible(c.oid)");
803806

@@ -1961,20 +1964,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
19611964
appendPQExpBuffer(&buf, "'i',");
19621965
if (showSeq)
19631966
appendPQExpBuffer(&buf, "'S',");
1964-
if (showSystem && showTables)
1967+
if (showSystem)
19651968
appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <= 8.1.X */
19661969
appendPQExpBuffer(&buf, "''"); /* dummy */
19671970
appendPQExpBuffer(&buf, ")\n");
19681971

1969-
/*
1970-
* If showSystem is specified, show only system objects (those in
1971-
* pg_catalog). Otherwise, suppress system objects, including those in
1972-
* pg_catalog and pg_toast. (We don't want to hide temp tables though.)
1973-
*/
1974-
if (showSystem)
1975-
appendPQExpBuffer(&buf,
1976-
" AND n.nspname = 'pg_catalog'\n");
1977-
else
1972+
if (!showSystem)
1973+
/* Exclude system and pg_toast objects, but show temp tables */
19781974
appendPQExpBuffer(&buf,
19791975
" AND n.nspname <> 'pg_catalog'\n"
19801976
" AND n.nspname !~ '^pg_toast'\n");

src/bin/psql/describe.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.38 2009/01/06 21:10:30 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.39 2009/01/20 02:13:42 momjian Exp $
77
*/
88
#ifndef DESCRIBE_H
99
#define DESCRIBE_H
@@ -34,7 +34,7 @@ extern bool permissionsList(const char *pattern);
3434
extern bool objectDescription(const char *pattern, bool showSystem);
3535

3636
/* \d foo */
37-
extern bool describeTableDetails(const char *pattern, bool verbose);
37+
extern bool describeTableDetails(const char *pattern, bool verbose, bool showSystem);
3838

3939
/* \dF */
4040
extern bool listTSConfigs(const char *pattern, bool verbose);

0 commit comments

Comments
 (0)