Skip to content

Commit 9491c82

Browse files
committed
This makes all the \dX commands (most importantly to most: \df) work
like \dt does, in that it requires a \dXS to see system items. Greg Sabino Mullane
1 parent e825fac commit 9491c82

File tree

4 files changed

+111
-62
lines changed

4 files changed

+111
-62
lines changed

src/bin/psql/command.c

Lines changed: 12 additions & 11 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.200 2009/01/01 17:23:54 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.201 2009/01/06 21:10:30 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -327,13 +327,14 @@ exec_command(const char *cmd,
327327
else if (cmd[0] == 'd')
328328
{
329329
char *pattern;
330-
bool show_verbose;
330+
bool show_verbose, show_system;
331331

332332
/* We don't do SQLID reduction on the pattern yet */
333333
pattern = psql_scan_slash_option(scan_state,
334334
OT_NORMAL, NULL, true);
335335

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

338339
switch (cmd[1])
339340
{
@@ -343,28 +344,28 @@ exec_command(const char *cmd,
343344
success = describeTableDetails(pattern, show_verbose);
344345
else
345346
/* standard listing of interesting things */
346-
success = listTables("tvs", NULL, show_verbose);
347+
success = listTables("tvs", NULL, show_verbose, show_system);
347348
break;
348349
case 'a':
349-
success = describeAggregates(pattern, show_verbose);
350+
success = describeAggregates(pattern, show_verbose, show_system);
350351
break;
351352
case 'b':
352353
success = describeTablespaces(pattern, show_verbose);
353354
break;
354355
case 'c':
355-
success = listConversions(pattern);
356+
success = listConversions(pattern, show_system);
356357
break;
357358
case 'C':
358359
success = listCasts(pattern);
359360
break;
360361
case 'd':
361-
success = objectDescription(pattern);
362+
success = objectDescription(pattern, show_system);
362363
break;
363364
case 'D':
364-
success = listDomains(pattern);
365+
success = listDomains(pattern, show_system);
365366
break;
366367
case 'f':
367-
success = describeFunctions(pattern, show_verbose);
368+
success = describeFunctions(pattern, show_verbose, show_system);
368369
break;
369370
case 'g':
370371
/* no longer distinct from \du */
@@ -377,20 +378,20 @@ exec_command(const char *cmd,
377378
success = listSchemas(pattern, show_verbose);
378379
break;
379380
case 'o':
380-
success = describeOperators(pattern);
381+
success = describeOperators(pattern, show_system);
381382
break;
382383
case 'p':
383384
success = permissionsList(pattern);
384385
break;
385386
case 'T':
386-
success = describeTypes(pattern, show_verbose);
387+
success = describeTypes(pattern, show_verbose, show_system);
387388
break;
388389
case 't':
389390
case 'v':
390391
case 'i':
391392
case 's':
392393
case 'S':
393-
success = listTables(&cmd[1], pattern, show_verbose);
394+
success = listTables(&cmd[1], pattern, show_verbose, show_system);
394395
break;
395396
case 'u':
396397
success = describeRoles(pattern, show_verbose);

src/bin/psql/describe.c

Lines changed: 58 additions & 15 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.193 2009/01/01 17:23:54 momjian Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.194 2009/01/06 21:10:30 momjian Exp $
1212
*/
1313
#include "postgres_fe.h"
1414

@@ -53,7 +53,7 @@ static void printACLColumn(PQExpBuffer buf, const char *colname);
5353
* Takes an optional regexp to select particular aggregates
5454
*/
5555
bool
56-
describeAggregates(const char *pattern, bool verbose)
56+
describeAggregates(const char *pattern, bool verbose, bool showSystem)
5757
{
5858
PQExpBufferData buf;
5959
PGresult *res;
@@ -76,7 +76,7 @@ describeAggregates(const char *pattern, bool verbose)
7676
" ELSE\n"
7777
" pg_catalog.array_to_string(ARRAY(\n"
7878
" SELECT\n"
79-
" pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
79+
" pg_catalog.format_type(p.proargtypes[s.i], NULL)\n"
8080
" FROM\n"
8181
" pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
8282
" ), ', ')\n"
@@ -94,6 +94,9 @@ describeAggregates(const char *pattern, bool verbose)
9494
"WHERE p.proisagg\n",
9595
gettext_noop("Description"));
9696

97+
if (!showSystem)
98+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
99+
97100
processSQLNamePattern(pset.db, &buf, pattern, true, false,
98101
"n.nspname", "p.proname", NULL,
99102
"pg_catalog.pg_function_is_visible(p.oid)");
@@ -182,7 +185,7 @@ describeTablespaces(const char *pattern, bool verbose)
182185
* Takes an optional regexp to select particular functions
183186
*/
184187
bool
185-
describeFunctions(const char *pattern, bool verbose)
188+
describeFunctions(const char *pattern, bool verbose, bool showSystem)
186189
{
187190
PQExpBufferData buf;
188191
PGresult *res;
@@ -278,6 +281,9 @@ describeFunctions(const char *pattern, bool verbose)
278281
" AND p.proargtypes[0] IS DISTINCT FROM 'pg_catalog.cstring'::pg_catalog.regtype\n"
279282
" AND NOT p.proisagg\n");
280283

284+
if (!showSystem)
285+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
286+
281287
processSQLNamePattern(pset.db, &buf, pattern, true, false,
282288
"n.nspname", "p.proname", NULL,
283289
"pg_catalog.pg_function_is_visible(p.oid)");
@@ -306,7 +312,7 @@ describeFunctions(const char *pattern, bool verbose)
306312
* describe types
307313
*/
308314
bool
309-
describeTypes(const char *pattern, bool verbose)
315+
describeTypes(const char *pattern, bool verbose, bool showSystem)
310316
{
311317
PQExpBufferData buf;
312318
PGresult *res;
@@ -366,6 +372,9 @@ describeTypes(const char *pattern, bool verbose)
366372
else
367373
appendPQExpBuffer(&buf, " AND t.typname !~ '^_'\n");
368374

375+
if (!showSystem)
376+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
377+
369378
/* Match name pattern against either internal or external name */
370379
processSQLNamePattern(pset.db, &buf, pattern, true, false,
371380
"n.nspname", "t.typname",
@@ -393,7 +402,7 @@ describeTypes(const char *pattern, bool verbose)
393402
/* \do
394403
*/
395404
bool
396-
describeOperators(const char *pattern)
405+
describeOperators(const char *pattern, bool showSystem)
397406
{
398407
PQExpBufferData buf;
399408
PGresult *res;
@@ -418,7 +427,10 @@ describeOperators(const char *pattern)
418427
gettext_noop("Result type"),
419428
gettext_noop("Description"));
420429

421-
processSQLNamePattern(pset.db, &buf, pattern, false, true,
430+
if (!showSystem)
431+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
432+
433+
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, true,
422434
"n.nspname", "o.oprname", NULL,
423435
"pg_catalog.pg_operator_is_visible(o.oid)");
424436

@@ -580,7 +592,7 @@ permissionsList(const char *pattern)
580592
* lists of things, there are other \d? commands.
581593
*/
582594
bool
583-
objectDescription(const char *pattern)
595+
objectDescription(const char *pattern, bool showSystem)
584596
{
585597
PQExpBufferData buf;
586598
PGresult *res;
@@ -607,6 +619,10 @@ objectDescription(const char *pattern)
607619
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
608620
" WHERE p.proisagg\n",
609621
gettext_noop("aggregate"));
622+
623+
if (!showSystem)
624+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
625+
610626
processSQLNamePattern(pset.db, &buf, pattern, true, false,
611627
"n.nspname", "p.proname", NULL,
612628
"pg_catalog.pg_function_is_visible(p.oid)");
@@ -626,6 +642,10 @@ objectDescription(const char *pattern)
626642
" OR p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype)\n"
627643
" AND NOT p.proisagg\n",
628644
gettext_noop("function"));
645+
646+
if (!showSystem)
647+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
648+
629649
processSQLNamePattern(pset.db, &buf, pattern, true, false,
630650
"n.nspname", "p.proname", NULL,
631651
"pg_catalog.pg_function_is_visible(p.oid)");
@@ -640,7 +660,11 @@ objectDescription(const char *pattern)
640660
" FROM pg_catalog.pg_operator o\n"
641661
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
642662
gettext_noop("operator"));
643-
processSQLNamePattern(pset.db, &buf, pattern, false, false,
663+
664+
if (!showSystem)
665+
appendPQExpBuffer(&buf, " WHERE n.nspname <> 'pg_catalog'\n");
666+
667+
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
644668
"n.nspname", "o.oprname", NULL,
645669
"pg_catalog.pg_operator_is_visible(o.oid)");
646670

@@ -654,7 +678,11 @@ objectDescription(const char *pattern)
654678
" FROM pg_catalog.pg_type t\n"
655679
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
656680
gettext_noop("data type"));
657-
processSQLNamePattern(pset.db, &buf, pattern, false, false,
681+
682+
if (!showSystem)
683+
appendPQExpBuffer(&buf, " WHERE n.nspname <> 'pg_catalog'\n");
684+
685+
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
658686
"n.nspname", "pg_catalog.format_type(t.oid, NULL)",
659687
NULL,
660688
"pg_catalog.pg_type_is_visible(t.oid)");
@@ -675,6 +703,9 @@ objectDescription(const char *pattern)
675703
gettext_noop("view"),
676704
gettext_noop("index"),
677705
gettext_noop("sequence"));
706+
if (!showSystem)
707+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
708+
678709
processSQLNamePattern(pset.db, &buf, pattern, true, false,
679710
"n.nspname", "c.relname", NULL,
680711
"pg_catalog.pg_table_is_visible(c.oid)");
@@ -691,6 +722,10 @@ objectDescription(const char *pattern)
691722
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
692723
" WHERE r.rulename != '_RETURN'\n",
693724
gettext_noop("rule"));
725+
726+
if (!showSystem)
727+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
728+
694729
/* XXX not sure what to do about visibility rule here? */
695730
processSQLNamePattern(pset.db, &buf, pattern, true, false,
696731
"n.nspname", "r.rulename", NULL,
@@ -707,8 +742,11 @@ objectDescription(const char *pattern)
707742
" JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
708743
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
709744
gettext_noop("trigger"));
745+
if (!showSystem)
746+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
747+
710748
/* XXX not sure what to do about visibility rule here? */
711-
processSQLNamePattern(pset.db, &buf, pattern, false, false,
749+
processSQLNamePattern(pset.db, &buf, pattern, !showSystem, false,
712750
"n.nspname", "t.tgname", NULL,
713751
"pg_catalog.pg_table_is_visible(c.oid)");
714752

@@ -1856,13 +1894,12 @@ add_role_attribute(PQExpBuffer buf, const char *const str)
18561894
* (any order of the above is fine)
18571895
*/
18581896
bool
1859-
listTables(const char *tabtypes, const char *pattern, bool verbose)
1897+
listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
18601898
{
18611899
bool showTables = strchr(tabtypes, 't') != NULL;
18621900
bool showIndexes = strchr(tabtypes, 'i') != NULL;
18631901
bool showViews = strchr(tabtypes, 'v') != NULL;
18641902
bool showSeq = strchr(tabtypes, 's') != NULL;
1865-
bool showSystem = strchr(tabtypes, 'S') != NULL;
18661903

18671904
PQExpBufferData buf;
18681905
PGresult *res;
@@ -1981,7 +2018,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
19812018
* Describes domains.
19822019
*/
19832020
bool
1984-
listDomains(const char *pattern)
2021+
listDomains(const char *pattern, bool showSystem)
19852022
{
19862023
PQExpBufferData buf;
19872024
PGresult *res;
@@ -2009,6 +2046,9 @@ listDomains(const char *pattern)
20092046
gettext_noop("Modifier"),
20102047
gettext_noop("Check"));
20112048

2049+
if (!showSystem)
2050+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
2051+
20122052
processSQLNamePattern(pset.db, &buf, pattern, true, false,
20132053
"n.nspname", "t.typname", NULL,
20142054
"pg_catalog.pg_type_is_visible(t.oid)");
@@ -2036,7 +2076,7 @@ listDomains(const char *pattern)
20362076
* Describes conversions.
20372077
*/
20382078
bool
2039-
listConversions(const char *pattern)
2079+
listConversions(const char *pattern, bool showSystem)
20402080
{
20412081
PQExpBufferData buf;
20422082
PGresult *res;
@@ -2061,6 +2101,9 @@ listConversions(const char *pattern)
20612101
gettext_noop("yes"), gettext_noop("no"),
20622102
gettext_noop("Default?"));
20632103

2104+
if (!showSystem)
2105+
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n");
2106+
20642107
processSQLNamePattern(pset.db, &buf, pattern, true, false,
20652108
"n.nspname", "c.conname", NULL,
20662109
"pg_catalog.pg_conversion_is_visible(c.oid)");

src/bin/psql/describe.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.37 2009/01/01 17:23:55 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.38 2009/01/06 21:10:30 momjian Exp $
77
*/
88
#ifndef DESCRIBE_H
99
#define DESCRIBE_H
1010

1111

1212
/* \da */
13-
extern bool describeAggregates(const char *pattern, bool verbose);
13+
extern bool describeAggregates(const char *pattern, bool verbose, bool showSystem);
1414

1515
/* \db */
1616
extern bool describeTablespaces(const char *pattern, bool verbose);
1717

1818
/* \df */
19-
extern bool describeFunctions(const char *pattern, bool verbose);
19+
extern bool describeFunctions(const char *pattern, bool verbose, bool showSystem);
2020

2121
/* \dT */
22-
extern bool describeTypes(const char *pattern, bool verbose);
22+
extern bool describeTypes(const char *pattern, bool verbose, bool showSystem);
2323

2424
/* \do */
25-
extern bool describeOperators(const char *pattern);
25+
extern bool describeOperators(const char *pattern, bool showSystem);
2626

2727
/* \du, \dg */
2828
extern bool describeRoles(const char *pattern, bool verbose);
@@ -31,7 +31,7 @@ extern bool describeRoles(const char *pattern, bool verbose);
3131
extern bool permissionsList(const char *pattern);
3232

3333
/* \dd */
34-
extern bool objectDescription(const char *pattern);
34+
extern bool objectDescription(const char *pattern, bool showSystem);
3535

3636
/* \d foo */
3737
extern bool describeTableDetails(const char *pattern, bool verbose);
@@ -52,13 +52,13 @@ extern bool listTSTemplates(const char *pattern, bool verbose);
5252
extern bool listAllDbs(bool verbose);
5353

5454
/* \dt, \di, \ds, \dS, etc. */
55-
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose);
55+
extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem);
5656

5757
/* \dD */
58-
extern bool listDomains(const char *pattern);
58+
extern bool listDomains(const char *pattern, bool showSystem);
5959

6060
/* \dc */
61-
extern bool listConversions(const char *pattern);
61+
extern bool listConversions(const char *pattern, bool showSystem);
6262

6363
/* \dC */
6464
extern bool listCasts(const char *pattern);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy