3
3
*
4
4
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
5
5
*
6
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.89 2003/12/01 22:11:06 momjian Exp $
6
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.90 2003/12/01 22:21:54 momjian Exp $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "describe.h"
@@ -1276,12 +1276,13 @@ describeUsers(const char *pattern)
1276
1276
" WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n"
1277
1277
" WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
1278
1278
" ELSE CAST('' AS pg_catalog.text)\n"
1279
- " END AS \"%s\"\n"
1279
+ " END AS \"%s\",\n"
1280
+ " ARRAY(SELECT g.groname FROM pg_catalog.pg_group g WHERE u.usesysid = ANY(g.grolist)) as \"%s\"\n"
1280
1281
"FROM pg_catalog.pg_user u\n" ,
1281
1282
_ ("User name" ), _ ("User ID" ),
1282
1283
_ ("superuser, create database" ),
1283
1284
_ ("superuser" ), _ ("create database" ),
1284
- _ ("Attributes" ));
1285
+ _ ("Attributes" ), _ ( "Groups" ) );
1285
1286
1286
1287
processNamePattern (& buf , pattern , false, false,
1287
1288
NULL , "u.usename" , NULL , NULL );
@@ -1303,6 +1304,46 @@ describeUsers(const char *pattern)
1303
1304
}
1304
1305
1305
1306
1307
+ /*
1308
+ * \dg
1309
+ *
1310
+ * Describes groups.
1311
+ */
1312
+ bool
1313
+ describeGroups (const char * pattern )
1314
+ {
1315
+ PQExpBufferData buf ;
1316
+ PGresult * res ;
1317
+ printQueryOpt myopt = pset .popt ;
1318
+
1319
+ initPQExpBuffer (& buf );
1320
+
1321
+ printfPQExpBuffer (& buf ,
1322
+ "SELECT g.groname AS \"%s\",\n"
1323
+ " g.grosysid AS \"%s\"\n"
1324
+ "FROM pg_catalog.pg_group g\n" ,
1325
+ _ ("Group name" ), _ ("Group ID" ));
1326
+
1327
+ processNamePattern (& buf , pattern , false, false,
1328
+ NULL , "g.groname" , NULL , NULL );
1329
+
1330
+ appendPQExpBuffer (& buf , "ORDER BY 1;" );
1331
+
1332
+ res = PSQLexec (buf .data , false);
1333
+ termPQExpBuffer (& buf );
1334
+ if (!res )
1335
+ return false;
1336
+
1337
+ myopt .nullPrint = NULL ;
1338
+ myopt .title = _ ("List of database groups" );
1339
+
1340
+ printQuery (res , & myopt , pset .queryFout );
1341
+
1342
+ PQclear (res );
1343
+ return true;
1344
+ }
1345
+
1346
+
1306
1347
/*
1307
1348
* listTables()
1308
1349
*
0 commit comments