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 */
5555bool
56- describeAggregates (const char * pattern ,bool verbose )
56+ describeAggregates (const char * pattern ,bool verbose , bool showSystem )
5757{
5858PQExpBufferData buf ;
5959PGresult * 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" ,
9595gettext_noop ("Description" ));
9696
97+ if (!showSystem )
98+ appendPQExpBuffer (& buf ," AND n.nspname <> 'pg_catalog'\n" );
99+
97100processSQLNamePattern (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 */
184187bool
185- describeFunctions (const char * pattern ,bool verbose )
188+ describeFunctions (const char * pattern ,bool verbose , bool showSystem )
186189{
187190PQExpBufferData buf ;
188191PGresult * 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+
281287processSQLNamePattern (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 */
308314bool
309- describeTypes (const char * pattern ,bool verbose )
315+ describeTypes (const char * pattern ,bool verbose , bool showSystem )
310316{
311317PQExpBufferData buf ;
312318PGresult * res ;
@@ -366,6 +372,9 @@ describeTypes(const char *pattern, bool verbose)
366372else
367373appendPQExpBuffer (& 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 */
370379processSQLNamePattern (pset .db ,& buf ,pattern , true, false,
371380"n.nspname" ,"t.typname" ,
@@ -393,7 +402,7 @@ describeTypes(const char *pattern, bool verbose)
393402/* \do
394403 */
395404bool
396- describeOperators (const char * pattern )
405+ describeOperators (const char * pattern , bool showSystem )
397406{
398407PQExpBufferData buf ;
399408PGresult * res ;
@@ -418,7 +427,10 @@ describeOperators(const char *pattern)
418427gettext_noop ("Result type" ),
419428gettext_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 */
582594bool
583- objectDescription (const char * pattern )
595+ objectDescription (const char * pattern , bool showSystem )
584596{
585597PQExpBufferData buf ;
586598PGresult * 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" ,
609621gettext_noop ("aggregate" ));
622+
623+ if (!showSystem )
624+ appendPQExpBuffer (& buf ," AND n.nspname <> 'pg_catalog'\n" );
625+
610626processSQLNamePattern (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" ,
628644gettext_noop ("function" ));
645+
646+ if (!showSystem )
647+ appendPQExpBuffer (& buf ," AND n.nspname <> 'pg_catalog'\n" );
648+
629649processSQLNamePattern (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" ,
642662gettext_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" ,
656680gettext_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)" ,
659687NULL ,
660688"pg_catalog.pg_type_is_visible(t.oid)" );
@@ -675,6 +703,9 @@ objectDescription(const char *pattern)
675703gettext_noop ("view" ),
676704gettext_noop ("index" ),
677705gettext_noop ("sequence" ));
706+ if (!showSystem )
707+ appendPQExpBuffer (& buf ," AND n.nspname <> 'pg_catalog'\n" );
708+
678709processSQLNamePattern (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" ,
693724gettext_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? */
695730processSQLNamePattern (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" ,
709744gettext_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 */
18581896bool
1859- listTables (const char * tabtypes ,const char * pattern ,bool verbose )
1897+ listTables (const char * tabtypes ,const char * pattern ,bool verbose , bool showSystem )
18601898{
18611899bool showTables = strchr (tabtypes ,'t' )!= NULL ;
18621900bool showIndexes = strchr (tabtypes ,'i' )!= NULL ;
18631901bool showViews = strchr (tabtypes ,'v' )!= NULL ;
18641902bool showSeq = strchr (tabtypes ,'s' )!= NULL ;
1865- bool showSystem = strchr (tabtypes ,'S' )!= NULL ;
18661903
18671904PQExpBufferData buf ;
18681905PGresult * res ;
@@ -1981,7 +2018,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
19812018 * Describes domains.
19822019 */
19832020bool
1984- listDomains (const char * pattern )
2021+ listDomains (const char * pattern , bool showSystem )
19852022{
19862023PQExpBufferData buf ;
19872024PGresult * res ;
@@ -2009,6 +2046,9 @@ listDomains(const char *pattern)
20092046gettext_noop ("Modifier" ),
20102047gettext_noop ("Check" ));
20112048
2049+ if (!showSystem )
2050+ appendPQExpBuffer (& buf ," AND n.nspname <> 'pg_catalog'\n" );
2051+
20122052processSQLNamePattern (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 */
20382078bool
2039- listConversions (const char * pattern )
2079+ listConversions (const char * pattern , bool showSystem )
20402080{
20412081PQExpBufferData buf ;
20422082PGresult * res ;
@@ -2061,6 +2101,9 @@ listConversions(const char *pattern)
20612101gettext_noop ("yes" ),gettext_noop ("no" ),
20622102gettext_noop ("Default?" ));
20632103
2104+ if (!showSystem )
2105+ appendPQExpBuffer (& buf ," AND n.nspname <> 'pg_catalog'\n" );
2106+
20642107processSQLNamePattern (pset .db ,& buf ,pattern , true, false,
20652108"n.nspname" ,"c.conname" ,NULL ,
20662109"pg_catalog.pg_conversion_is_visible(c.oid)" );