7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.67 1997/06/01 15:38:42 scrappy Exp $
10
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.68 1997/06/01 15:53:24 scrappy Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -81,7 +81,7 @@ static void handleCopyOut(PGresult * res, bool quiet, FILE * copystream);
81
81
static void
82
82
handleCopyIn (PGresult * res ,const bool mustprompt ,
83
83
FILE * copystream );
84
- static int tableList (PsqlSettings * ps ,bool deep_tablelist );
84
+ static int tableList (PsqlSettings * ps ,bool deep_tablelist , char table_index_both );
85
85
static int tableDesc (PsqlSettings * ps ,char * table );
86
86
static int rightsList (PsqlSettings * ps );
87
87
static void prompt_for_password (char * username ,char * password );
@@ -158,7 +158,9 @@ slashUsage(PsqlSettings * ps)
158
158
fprintf (stderr ," \\C [<captn>] -- set html3 caption (currently '%s')\n" ,ps -> opt .caption ?ps -> opt .caption :"" );
159
159
fprintf (stderr ," \\connect <dbname> <user> -- connect to new database (currently '%s')\n" ,PQdb (ps -> db ));
160
160
fprintf (stderr ," \\copy table {from | to} <fname>\n" );
161
- fprintf (stderr ," \\d [<table>] -- list tables in database or columns in <table>, * for all\n" );
161
+ fprintf (stderr ," \\d [<table>] -- list tables and indicies in database or columns in <table>, * for all\n" );
162
+ fprintf (stderr ," \\di -- list only indicies in database\n" );
163
+ fprintf (stderr ," \\dt -- list only tables in database\n" );
162
164
fprintf (stderr ," \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n" );
163
165
fprintf (stderr ," \\f [<sep>] -- change field separater (currently '%s')\n" ,ps -> opt .fieldSep );
164
166
fprintf (stderr ," \\g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]\n" );
@@ -225,7 +227,7 @@ listAllDbs(PsqlSettings * ps)
225
227
*
226
228
*/
227
229
int
228
- tableList (PsqlSettings * ps ,bool deep_tablelist )
230
+ tableList (PsqlSettings * ps ,bool deep_tablelist , char table_index_both )
229
231
{
230
232
char listbuf [256 ];
231
233
int nColumns ;
@@ -238,7 +240,15 @@ tableList(PsqlSettings * ps, bool deep_tablelist)
238
240
listbuf [0 ]= '\0' ;
239
241
strcat (listbuf ,"SELECT usename, relname, relkind, relhasrules" );
240
242
strcat (listbuf ," FROM pg_class, pg_user " );
241
- strcat (listbuf ,"WHERE ( relkind = 'r' OR relkind = 'i') " );
243
+ switch (table_index_both ) {
244
+ case 't' :strcat (listbuf ,"WHERE ( relkind = 'r') " );
245
+ break ;
246
+ case 'i' :strcat (listbuf ,"WHERE ( relkind = 'i') " );
247
+ break ;
248
+ case 'b' :
249
+ default :strcat (listbuf ,"WHERE ( relkind = 'r' OR relkind = 'i') " );
250
+ break ;
251
+ }
242
252
strcat (listbuf ," and relname !~ '^pg_'" );
243
253
strcat (listbuf ," and relname !~ '^Inv[0-9]+'" );
244
254
/*
@@ -299,7 +309,15 @@ tableList(PsqlSettings * ps, bool deep_tablelist)
299
309
return (0 );
300
310
301
311
}else {
302
- fprintf (stderr ,"Couldn't find any tables!\n" );
312
+ switch (table_index_both ) {
313
+ case 't' :fprintf (stderr ,"Couldn't find any tables!\n" );
314
+ break ;
315
+ case 'i' :fprintf (stderr ,"Couldn't find any indicies!\n" );
316
+ break ;
317
+ case 'b' :
318
+ default :fprintf (stderr ,"Couldn't find any tables or indicies!\n" );
319
+ break ;
320
+ }
303
321
return (-1 );
304
322
}
305
323
}
@@ -1151,14 +1169,16 @@ HandleSlashCmds(PsqlSettings * settings,
1151
1169
}
1152
1170
break ;
1153
1171
case 'd' :/* \d describe tables or columns in a table */
1154
- if (!optarg ) {
1155
- tableList (settings ,0 );
1156
- break ;
1157
- }
1158
- if (strcmp (optarg ,"*" )== 0 ) {
1159
- tableList (settings ,0 );
1160
- tableList (settings ,1 );
1161
- }else {
1172
+ if (strncmp (cmd ,"dt" ,2 )== 0 ) {/* only tables */
1173
+ tableList (settings ,0 ,'t' );
1174
+ }else if (strncmp (cmd ,"di" ,2 )== 0 ) {/* only tables */
1175
+ tableList (settings ,0 ,'i' );
1176
+ }else if (!optarg ) {/* show'em both */
1177
+ tableList (settings ,0 ,'b' );
1178
+ }else if (strcmp (optarg ,"*" )== 0 ) {/* show everything */
1179
+ tableList (settings ,0 ,'b' );
1180
+ tableList (settings ,1 ,'b' );
1181
+ }else {/* describe the specified table */
1162
1182
tableDesc (settings ,optarg );
1163
1183
}
1164
1184
break ;