, * for all\n");
+ fprintf(stderr, " \\di -- list only indicies in database\n");
+ fprintf(stderr, " \\dt -- list only tables in database\n");
fprintf(stderr, " \\e [] -- edit the current query buffer or , \\E execute too\n");
fprintf(stderr, " \\f [] -- change field separater (currently '%s')\n", ps->opt.fieldSep);
fprintf(stderr, " \\g [] [|] -- send query to backend [and results in or pipe]\n");
*
*/
int
-tableList(PsqlSettings * ps, bool deep_tablelist)
+tableList(PsqlSettings * ps, bool deep_tablelist, char table_index_both)
{
char listbuf[256];
int nColumns;
listbuf[0] = '\0';
strcat(listbuf, "SELECT usename, relname, relkind, relhasrules");
strcat(listbuf, " FROM pg_class, pg_user ");
- strcat(listbuf, "WHERE ( relkind = 'r' OR relkind = 'i') ");
+ switch (table_index_both) {
+ case 't': strcat(listbuf, "WHERE ( relkind = 'r') ");
+ break;
+ case 'i': strcat(listbuf, "WHERE ( relkind = 'i') ");
+ break;
+ case 'b':
+ default: strcat(listbuf, "WHERE ( relkind = 'r' OR relkind = 'i') ");
+ break;
+ }
strcat(listbuf, " and relname !~ '^pg_'");
strcat(listbuf, " and relname !~ '^Inv[0-9]+'");
/*
return (0);
} else {
- fprintf(stderr, "Couldn't find any tables!\n");
+ switch (table_index_both) {
+ case 't': fprintf(stderr, "Couldn't find any tables!\n");
+ break;
+ case 'i': fprintf(stderr, "Couldn't find any indicies!\n");
+ break;
+ case 'b':
+ default: fprintf(stderr, "Couldn't find any tables or indicies!\n");
+ break;
+ }
return (-1);
}
}
}
break;
case 'd': /* \d describe tables or columns in a table */
- if (!optarg) {
- tableList(settings, 0);
- break;
- }
- if (strcmp(optarg, "*") == 0) {
- tableList(settings, 0);
- tableList(settings, 1);
- } else {
+ if (strncmp(cmd, "dt", 2) == 0) { /* only tables */
+ tableList(settings, 0, 't');
+ } else if (strncmp(cmd, "di", 2) == 0) { /* only tables */
+ tableList(settings, 0, 'i');
+ } else if (!optarg) { /* show'em both */
+ tableList(settings, 0, 'b');
+ } else if (strcmp(optarg, "*") == 0) { /* show everything */
+ tableList(settings, 0, 'b');
+ tableList(settings, 1, 'b');
+ } else { /* describe the specified table */
tableDesc(settings, optarg);
}
break;