Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff038a5

Browse files
committed
From: Darren King <aixssd!darrenk@abs.net>
Subject: [PATCHES] psql - \dt,\di commands.I sent this a couple of months ago in re a request by MaximKozin, but I had the patch reversed, creating some confusionover applying it.Here's a more complete version.Adds \dt to list only tables/views and \di to list onlyindicies. \d will still work as before.
1 parent187e0f2 commitff038a5

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

‎src/bin/psql/psql.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* 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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -81,7 +81,7 @@ static void handleCopyOut(PGresult * res, bool quiet, FILE * copystream);
8181
staticvoid
8282
handleCopyIn(PGresult*res,constboolmustprompt,
8383
FILE*copystream);
84-
staticinttableList(PsqlSettings*ps,booldeep_tablelist);
84+
staticinttableList(PsqlSettings*ps,booldeep_tablelist,chartable_index_both);
8585
staticinttableDesc(PsqlSettings*ps,char*table);
8686
staticintrightsList(PsqlSettings*ps);
8787
staticvoidprompt_for_password(char*username,char*password);
@@ -158,7 +158,9 @@ slashUsage(PsqlSettings * ps)
158158
fprintf(stderr," \\C [<captn>] -- set html3 caption (currently '%s')\n",ps->opt.caption ?ps->opt.caption :"");
159159
fprintf(stderr," \\connect <dbname> <user> -- connect to new database (currently '%s')\n",PQdb(ps->db));
160160
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");
162164
fprintf(stderr," \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n");
163165
fprintf(stderr," \\f [<sep>] -- change field separater (currently '%s')\n",ps->opt.fieldSep);
164166
fprintf(stderr," \\g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]\n");
@@ -225,7 +227,7 @@ listAllDbs(PsqlSettings * ps)
225227
*
226228
*/
227229
int
228-
tableList(PsqlSettings*ps,booldeep_tablelist)
230+
tableList(PsqlSettings*ps,booldeep_tablelist,chartable_index_both)
229231
{
230232
charlistbuf[256];
231233
intnColumns;
@@ -238,7 +240,15 @@ tableList(PsqlSettings * ps, bool deep_tablelist)
238240
listbuf[0]='\0';
239241
strcat(listbuf,"SELECT usename, relname, relkind, relhasrules");
240242
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+
}
242252
strcat(listbuf," and relname !~ '^pg_'");
243253
strcat(listbuf," and relname !~ '^Inv[0-9]+'");
244254
/*
@@ -299,7 +309,15 @@ tableList(PsqlSettings * ps, bool deep_tablelist)
299309
return (0);
300310

301311
}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+
}
303321
return (-1);
304322
}
305323
}
@@ -1151,14 +1169,16 @@ HandleSlashCmds(PsqlSettings * settings,
11511169
}
11521170
break;
11531171
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+
}elseif (strncmp(cmd,"di",2)==0) {/* only tables */
1175+
tableList(settings,0,'i');
1176+
}elseif (!optarg) {/* show'em both */
1177+
tableList(settings,0,'b');
1178+
}elseif (strcmp(optarg,"*")==0) {/* show everything */
1179+
tableList(settings,0,'b');
1180+
tableList(settings,1,'b');
1181+
}else {/* describe the specified table */
11621182
tableDesc(settings,optarg);
11631183
}
11641184
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp