88 *
99 * Copyright (c) 2000-2008, PostgreSQL Global Development Group
1010 *
11- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.190 2008/12/19 16:25:18 petere Exp $
11+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.191 2008/12/31 18:07:47 tgl Exp $
1212 */
1313#include "postgres_fe.h"
1414
@@ -37,6 +37,7 @@ static bool listTSConfigsVerbose(const char *pattern);
3737static bool describeOneTSConfig (const char * oid ,const char * nspname ,
3838const char * cfgname ,
3939const char * pnspname ,const char * prsname );
40+ static void printACLColumn (PQExpBuffer buf ,const char * colname );
4041
4142
4243/*----------------
@@ -142,9 +143,11 @@ describeTablespaces(const char *pattern, bool verbose)
142143gettext_noop ("Location" ));
143144
144145if (verbose )
145- appendPQExpBuffer (& buf ,
146- ",\n spcacl AS \"%s\"" ,
147- gettext_noop ("Access privileges" ));
146+ {
147+ appendPQExpBuffer (& buf ,",\n " );
148+ printACLColumn (& buf ,"spcacl" );
149+ }
150+
148151if (verbose && pset .sversion >=80200 )
149152appendPQExpBuffer (& buf ,
150153",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"" ,
@@ -464,9 +467,8 @@ listAllDbs(bool verbose)
464467" d.datctype as \"%s\",\n" ,
465468gettext_noop ("Collation" ),
466469gettext_noop ("Ctype" ));
467- appendPQExpBuffer (& buf ,
468- " d.datacl as \"%s\"" ,
469- gettext_noop ("Access Privileges" ));
470+ appendPQExpBuffer (& buf ," " );
471+ printACLColumn (& buf ,"d.datacl" );
470472if (verbose && pset .sversion >=80200 )
471473appendPQExpBuffer (& buf ,
472474",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
@@ -524,20 +526,14 @@ permissionsList(const char *pattern)
524526printfPQExpBuffer (& buf ,
525527"SELECT n.nspname as \"%s\",\n"
526528" c.relname as \"%s\",\n"
527- " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'S' THEN '%s' END as \"%s\",\n" ,
529+ " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'S' THEN '%s' END as \"%s\",\n"
530+ " " ,
528531gettext_noop ("Schema" ),
529532gettext_noop ("Name" ),
530533gettext_noop ("table" ),gettext_noop ("view" ),gettext_noop ("sequence" ),
531534gettext_noop ("Type" ));
532-
533- if (pset .sversion >=80100 )
534- appendPQExpBuffer (& buf ," pg_catalog.array_to_string(c.relacl, E'\\n') as \"%s\"\n" ,
535- gettext_noop ("Access privileges" ));
536- else
537- appendPQExpBuffer (& buf ," pg_catalog.array_to_string(c.relacl, '\\n') as \"%s\"\n" ,
538- gettext_noop ("Access privileges" ));
539-
540- appendPQExpBuffer (& buf ,"FROM pg_catalog.pg_class c\n"
535+ printACLColumn (& buf ,"c.relacl" );
536+ appendPQExpBuffer (& buf ,"\nFROM pg_catalog.pg_class c\n"
541537" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
542538"WHERE c.relkind IN ('r', 'v', 'S')\n" );
543539
@@ -2188,11 +2184,13 @@ listSchemas(const char *pattern, bool verbose)
21882184gettext_noop ("Owner" ));
21892185
21902186if (verbose )
2187+ {
2188+ appendPQExpBuffer (& buf ,",\n " );
2189+ printACLColumn (& buf ,"n.nspacl" );
21912190appendPQExpBuffer (& buf ,
2192- ",\n n.nspacl as \"%s\","
2193- " pg_catalog.obj_description(n.oid, 'pg_namespace') as \"%s\"" ,
2194- gettext_noop ("Access privileges" ),
2191+ ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"" ,
21952192gettext_noop ("Description" ));
2193+ }
21962194
21972195appendPQExpBuffer (& buf ,
21982196"\nFROM pg_catalog.pg_namespace n\n"
@@ -2803,21 +2801,23 @@ listForeignDataWrappers(const char *pattern, bool verbose)
28032801printfPQExpBuffer (& buf ,
28042802"SELECT fdwname AS \"%s\",\n"
28052803" pg_catalog.pg_get_userbyid(fdwowner) AS \"%s\",\n"
2806- " fdwlibrary AS \"%s\"\n " ,
2804+ " fdwlibrary AS \"%s\"" ,
28072805gettext_noop ("Name" ),
28082806gettext_noop ("Owner" ),
28092807gettext_noop ("Library" ));
28102808
28112809if (verbose )
2810+ {
2811+ appendPQExpBuffer (& buf ,",\n " );
2812+ printACLColumn (& buf ,"fdwacl" );
28122813appendPQExpBuffer (& buf ,
2813- ",\n fdwacl AS \"%s\","
2814- " fdwoptions AS \"%s\"" ,
2815- gettext_noop ("Access privileges" ),
2814+ ",\n fdwoptions AS \"%s\"" ,
28162815gettext_noop ("Options" ));
2816+ }
28172817
2818- appendPQExpBuffer (& buf ,"\nFROM pg_catalog.pg_foreign_data_wrapper WHERE 1=1 \n" );
2818+ appendPQExpBuffer (& buf ,"\nFROM pg_catalog.pg_foreign_data_wrapper\n" );
28192819
2820- processSQLNamePattern (pset .db ,& buf ,pattern ,true , false,
2820+ processSQLNamePattern (pset .db ,& buf ,pattern ,false , false,
28212821NULL ,"fdwname" ,NULL ,NULL );
28222822
28232823appendPQExpBuffer (& buf ,"ORDER BY 1;" );
@@ -2840,7 +2840,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
28402840/*
28412841 * \des
28422842 *
2843- * Describes servers.
2843+ * Describesforeign-data servers.
28442844 */
28452845bool
28462846listForeignServers (const char * pattern ,bool verbose )
@@ -2853,27 +2853,30 @@ listForeignServers(const char *pattern, bool verbose)
28532853printfPQExpBuffer (& buf ,
28542854"SELECT s.srvname AS \"%s\",\n"
28552855" pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
2856- " f.fdwname AS \"%s\"\n " ,
2856+ " f.fdwname AS \"%s\"" ,
28572857gettext_noop ("Name" ),
28582858gettext_noop ("Owner" ),
28592859gettext_noop ("Foreign-data wrapper" ));
28602860
28612861if (verbose )
2862+ {
2863+ appendPQExpBuffer (& buf ,",\n " );
2864+ printACLColumn (& buf ,"s.srvacl" );
28622865appendPQExpBuffer (& buf ,
2863- ",\n s.srvacl AS \"%s\", "
2864- " s.srvtype AS \"%s\","
2865- " s.srvversion AS \"%s\","
2866+ ",\n"
2867+ " s.srvtype AS \"%s\",\n "
2868+ " s.srvversion AS \"%s\",\n "
28662869" s.srvoptions AS \"%s\"" ,
2867- gettext_noop ("Access privileges" ),
28682870gettext_noop ("Type" ),
28692871gettext_noop ("Version" ),
28702872gettext_noop ("Options" ));
2873+ }
28712874
28722875appendPQExpBuffer (& buf ,
2873- "\nFROM pg_foreign_server s\n"
2874- "JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n" );
2876+ "\nFROMpg_catalog. pg_foreign_server s\n"
2877+ " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n" );
28752878
2876- processSQLNamePattern (pset .db ,& buf ,pattern ,true , false,
2879+ processSQLNamePattern (pset .db ,& buf ,pattern ,false , false,
28772880NULL ,"s.srvname" ,NULL ,NULL );
28782881
28792882appendPQExpBuffer (& buf ,"ORDER BY 1;" );
@@ -2917,9 +2920,9 @@ listUserMappings(const char *pattern, bool verbose)
29172920",\n um.umoptions AS \"%s\"" ,
29182921gettext_noop ("Options" ));
29192922
2920- appendPQExpBuffer (& buf ,"\nFROM pg_catalog.pg_user_mappings um WHERE 1=1 \n" );
2923+ appendPQExpBuffer (& buf ,"\nFROM pg_catalog.pg_user_mappings um\n" );
29212924
2922- processSQLNamePattern (pset .db ,& buf ,pattern ,true , false,
2925+ processSQLNamePattern (pset .db ,& buf ,pattern ,false , false,
29232926NULL ,"um.srvname" ,"um.usename" ,NULL );
29242927
29252928appendPQExpBuffer (& buf ,"ORDER BY 1, 2;" );
@@ -2938,3 +2941,23 @@ listUserMappings(const char *pattern, bool verbose)
29382941PQclear (res );
29392942return true;
29402943}
2944+
2945+ /*
2946+ * printACLColumn
2947+ *
2948+ * Helper function for consistently formatting ACL (privilege) columns.
2949+ * The proper targetlist entry is appended to buf. Note lack of any
2950+ * whitespace or comma decoration.
2951+ */
2952+ static void
2953+ printACLColumn (PQExpBuffer buf ,const char * colname )
2954+ {
2955+ if (pset .sversion >=80100 )
2956+ appendPQExpBuffer (buf ,
2957+ "pg_catalog.array_to_string(%s, E'\\n') AS \"%s\"" ,
2958+ colname ,gettext_noop ("Access privileges" ));
2959+ else
2960+ appendPQExpBuffer (buf ,
2961+ "pg_catalog.array_to_string(%s, '\\n') AS \"%s\"" ,
2962+ colname ,gettext_noop ("Access privileges" ));
2963+ }