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

Commit4cbc06c

Browse files
committed
Add new psql \da, \do, and \dT options.
1 parent208dae3 commit4cbc06c

File tree

5 files changed

+106
-51
lines changed

5 files changed

+106
-51
lines changed

‎src/bin/initdb/initdb.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#
2727
#
2828
# IDENTIFICATION
29-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.25 1997/11/13 03:22:34 momjian Exp $
29+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.26 1997/11/14 21:37:35 momjian Exp $
3030
#
3131
#-------------------------------------------------------------------------
3232

@@ -346,11 +346,12 @@ fi
346346

347347
echo
348348

349+
echo"loading pg_description"
350+
echo"copy pg_description from '$TEMPLATE_DESCR'"| postgres -F -Q -D$PGDATA template1> /dev/null
351+
echo"copy pg_description from '$GLOBAL_DESCR'"| postgres -F -Q -D$PGDATA template1> /dev/null
352+
349353
echo"vacuuming template1"
350354
echo"vacuum"| postgres -F -Q -D$PGDATA template12>&1> /dev/null|\
351355
grep -v"^DEBUG:"
352356

353-
echo"loading pg_description"
354-
echo"copy pg_description from '$TEMPLATE_DESCR'"| postgres -F -Q -D$PGDATA template1> /dev/null
355-
echo"copy pg_description from '$GLOBAL_DESCR'"| postgres -F -Q -D$PGDATA template1> /dev/null
356357

‎src/bin/psql/psql.c

Lines changed: 89 additions & 43 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.104 1997/11/1405:57:35 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.105 1997/11/1421:37:41 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -135,14 +135,6 @@ HandleSlashCmds(PsqlSettings *pset,
135135
char*line,
136136
char*query);
137137
staticintMainLoop(PsqlSettings*pset,char*query,FILE*source);
138-
139-
/* probably should move this into libpq */
140-
void
141-
PQprint(FILE*fp,
142-
PGresult*res,
143-
PQprintOpt*po
144-
);
145-
146138
staticFILE*setFout(PsqlSettings*pset,char*fname);
147139

148140
/*
@@ -224,11 +216,14 @@ slashUsage(PsqlSettings *pset)
224216
fprintf(fout," \\C [<captn>] -- set html3 caption (currently '%s')\n",pset->opt.caption ?pset->opt.caption :"");
225217
fprintf(fout," \\connect <dbname|-> <user> -- connect to new database (currently '%s')\n",PQdb(pset->db));
226218
fprintf(fout," \\copy table {from | to} <fname>\n");
227-
fprintf(fout," \\d [<table>] -- list tables and indices in database or columns in <table>, * for all\n");
219+
fprintf(fout," \\d [<table>] -- list tables and indices, columns in <table>, or * for all\n");
220+
fprintf(fout," \\da -- list aggregates\n");
228221
fprintf(fout," \\dd [<object>]- list comment for table, field, type, function, or operator.\n");
229-
fprintf(fout," \\di -- list only indices in database\n");
230-
fprintf(fout," \\ds -- list only sequences in database\n");
231-
fprintf(fout," \\dt -- list only tables in database\n");
222+
fprintf(fout," \\di -- list only indices\n");
223+
fprintf(fout," \\do -- list operators\n");
224+
fprintf(fout," \\ds -- list only sequences\n");
225+
fprintf(fout," \\dt -- list only tables\n");
226+
fprintf(fout," \\dT -- list types\n");
232227
fprintf(fout," \\e [<fname>] -- edit the current query buffer or <fname>\n");
233228
fprintf(fout," \\E [<fname>] -- edit the current query buffer or <fname>, and execute\n");
234229
fprintf(fout," \\f [<sep>] -- change field separater (currently '%s')\n",pset->opt.fieldSep);
@@ -751,59 +746,45 @@ objectDescription(PsqlSettings *pset, char *object, FILE *fout)
751746
strcat(descbuf,"FROM pg_type, pg_description ");
752747
strcat(descbuf,"WHERE pg_type.typname = '");
753748
strcat(descbuf,object);
754-
strcat(descbuf,"'");
755-
strcat(descbuf,"andpg_type.oid = pg_description.objoid " );
749+
strcat(descbuf,"' and ");
750+
strcat(descbuf," pg_type.oid = pg_description.objoid " );
756751
if (!(res=PSQLexec(pset,descbuf)))
757752
return-1;
758-
elseif (PQntuples(res) <=0)
759753
{
760754
PQclear(res);
761755
descbuf[0]='\0';
762756
strcat(descbuf,"SELECT DISTINCT description ");
763-
strcat(descbuf,"FROMpg_type, pg_description ");
764-
strcat(descbuf,"WHEREpg_type.typname = '");
757+
strcat(descbuf,"FROMpg_proc, pg_description ");
758+
strcat(descbuf,"WHEREpg_proc.proname = '");
765759
strcat(descbuf,object);
766760
strcat(descbuf,"'" );
767-
strcat(descbuf," andpg_type.oid = pg_description.objoid " );
761+
strcat(descbuf," andpg_proc.oid = pg_description.objoid " );
768762
if (!(res=PSQLexec(pset,descbuf)))
769763
return-1;
770764
elseif (PQntuples(res) <=0)
771765
{
772766
PQclear(res);
773767
descbuf[0]='\0';
774768
strcat(descbuf,"SELECT DISTINCT description ");
775-
strcat(descbuf,"FROMpg_proc, pg_description ");
776-
strcat(descbuf,"WHEREpg_proc.proname = '");
769+
strcat(descbuf,"FROMpg_operator, pg_description ");
770+
strcat(descbuf,"WHEREpg_operator.oprname = '");
777771
strcat(descbuf,object);
778772
strcat(descbuf,"'" );
779-
strcat(descbuf," andpg_proc.oid = pg_description.objoid " );
773+
strcat(descbuf," andpg_operator.oid = pg_description.objoid " );
780774
if (!(res=PSQLexec(pset,descbuf)))
781775
return-1;
782776
elseif (PQntuples(res) <=0)
783777
{
784778
PQclear(res);
785779
descbuf[0]='\0';
786780
strcat(descbuf,"SELECT DISTINCT description ");
787-
strcat(descbuf,"FROMpg_operator, pg_description ");
788-
strcat(descbuf,"WHEREpg_operator.oprname = '");
781+
strcat(descbuf,"FROMpg_aggregate, pg_description ");
782+
strcat(descbuf,"WHEREpg_aggregate.aggname = '");
789783
strcat(descbuf,object);
790784
strcat(descbuf,"'" );
791-
strcat(descbuf," andpg_operator.oid = pg_description.objoid " );
785+
strcat(descbuf," andpg_aggregate.oid = pg_description.objoid " );
792786
if (!(res=PSQLexec(pset,descbuf)))
793787
return-1;
794-
elseif (PQntuples(res) <=0)
795-
{
796-
PQclear(res);
797-
descbuf[0]='\0';
798-
strcat(descbuf,"SELECT DISTINCT description ");
799-
strcat(descbuf,"FROM pg_aggregate, pg_description ");
800-
strcat(descbuf,"WHERE pg_aggregate.aggname = '");
801-
strcat(descbuf,object);
802-
strcat(descbuf,"'" );
803-
strcat(descbuf," and pg_aggregate.oid = pg_description.objoid " );
804-
if (!(res=PSQLexec(pset,descbuf)))
805-
return-1;
806-
}
807788
}
808789
}
809790
}
@@ -1584,7 +1565,7 @@ HandleSlashCmds(PsqlSettings *pset,
15841565
{
15851566
intstatus=CMD_SKIP_LINE;
15861567
char*optarg;
1587-
1568+
boolsuccess;
15881569
/*
15891570
* Pointer inside the <cmd> string to the argument of the slash
15901571
* command, assuming it is a one-character slash command. If it's not
@@ -1696,20 +1677,82 @@ HandleSlashCmds(PsqlSettings *pset,
16961677
}
16971678
}
16981679
break;
1699-
case'd':/* \d describe tables or columns in a
1700-
* table */
1701-
if (strncmp(cmd,"dd",2)==0)
1680+
case'd':/* \d describe database information */
1681+
if (strncmp(cmd,"da",2)==0)
1682+
/* aggregates */
1683+
SendQuery(&success,pset,"\
1684+
SELECTa.aggname AS aggname, \
1685+
t.typname AS typname, \
1686+
obj_description(a.oid) as description \
1687+
FROMpg_aggregate a, pg_type t \
1688+
WHEREa.aggbasetype = t.oid \
1689+
ORDER BY aggname, typname;",
1690+
false, false,0);
1691+
elseif (strncmp(cmd,"dd",2)==0)
17021692
/* descriptions */
17031693
objectDescription(pset,optarg+1,NULL);
17041694
elseif (strncmp(cmd,"di",2)==0)
17051695
/* only indices */
17061696
tableList(pset, false,'i');
1697+
elseif (strncmp(cmd,"do",2)==0)
1698+
{
1699+
/* operators */
1700+
SendQuery(&success,pset,"\
1701+
SELECTt0.typname AS result, \
1702+
t1.typname AS left_type, \
1703+
t2.typname AS right_type, \
1704+
o.oprname AS operatr, \
1705+
p.proname AS func_name, \
1706+
obj_description(o.oid) as description \
1707+
FROMpg_proc p, pg_type t0, \
1708+
pg_type t1, pg_type t2, \
1709+
pg_operator o \
1710+
WHEREp.prorettype = t0.oid AND \
1711+
RegprocToOid(o.oprcode) = p.oid AND \
1712+
p.pronargs = 2 AND \
1713+
o.oprleft = t1.oid AND \
1714+
o.oprright = t2.oid \
1715+
ORDER BY result, left_type, right_type, operatr;",
1716+
false, false,0);
1717+
SendQuery(&success,pset,"\
1718+
SELECTo.oprname AS left_unary, \
1719+
t.typname AS operand, \
1720+
r.typname AS return_type, \
1721+
obj_description(o.oid) as description \
1722+
FROMpg_operator o, pg_type t, pg_type r \
1723+
WHEREo.oprkind = 'l' AND \
1724+
o.oprright = t.oid AND \
1725+
o.oprresult = r.oid \
1726+
ORDER BY operand;",
1727+
false, false,0);
1728+
SendQuery(&success,pset,"\
1729+
SELECTo.oprname AS right_unary, \
1730+
t.typname AS operand, \
1731+
r.typname AS return_type, \
1732+
obj_description(o.oid) as description \
1733+
FROMpg_operator o, pg_type t, pg_type r \
1734+
WHEREo.oprkind = 'r' AND \
1735+
o.oprleft = t.oid AND \
1736+
o.oprresult = r.oid \
1737+
ORDER BY operand;",
1738+
false, false,0);
1739+
}
17071740
elseif (strncmp(cmd,"ds",2)==0)
17081741
/* only sequences */
17091742
tableList(pset, false,'S');
17101743
elseif (strncmp(cmd,"dt",2)==0)
17111744
/* only tables */
17121745
tableList(pset, false,'t');
1746+
elseif (strncmp(cmd,"dT",2)==0)
1747+
/* types */
1748+
SendQuery(&success,pset,"\
1749+
SELECTtypname AS type, \
1750+
obj_description(oid) as description \
1751+
FROMpg_type \
1752+
WHEREtyprelid = 0 AND \
1753+
typname !~ '^_.*' \
1754+
ORDER BY type;",
1755+
false, false,0);
17131756
elseif (!optarg)
17141757
/* show tables, sequences and indices */
17151758
tableList(pset, false,'b');
@@ -1718,9 +1761,12 @@ HandleSlashCmds(PsqlSettings *pset,
17181761
if (tableList(pset, false,'b')==0)
17191762
tableList(pset, true,'b');
17201763
}
1721-
else
1764+
elseif (strncmp(cmd,"d ",2)==0)
17221765
/* describe the specified table */
17231766
tableDesc(pset,optarg,NULL);
1767+
else
1768+
slashUsage(pset);
1769+
17241770
break;
17251771
case'e':/* edit */
17261772
{

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_proc.h,v 1.34 1997/11/13 03:23:07 momjian Exp $
9+
* $Id: pg_proc.h,v 1.35 1997/11/14 21:37:54 momjian Exp $
1010
*
1111
* NOTES
1212
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1649,6 +1649,8 @@ DATA(insert OID = 1346 ( int2 PGUID 14 f t f 1 f21 "25" 100 0 0 100 "sele
16491649
DESCR("");
16501650
DATA(insertOID=1347 (int4PGUID14ftf1f23"25"10000100"select text_int4($1)"- ));
16511651
DESCR("");
1652+
DATA(insertOID=1348 (obj_descriptionPGUID14ftf1f25"26"10000100"select description from pg_description where objoid = $1"- ));
1653+
DESCR("");
16521654

16531655
DATA(insertOID=1350 (datetimePGUID14ftf1f1184"1184"10000100"select $1"- ));
16541656
DESCR("");

‎src/man/psql.1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.14 1997/11/13 03:36:42 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.15 1997/11/14 21:38:16 momjian Exp $
44
.TH PSQL UNIX 1/20/96 PostgreSQL PostgreSQL
55
.SH NAME
66
psql\(em run the interactive query front-end
@@ -292,14 +292,20 @@ is specified, list the columns in
292292
If table name is
293293
.IR *,
294294
list all tables and column information for each tables.
295+
.IP"\eda"
296+
List aggregates.
295297
.IP"\edd object"
296298
List the description of the table, table.column, type, operator, or aggregate.
297299
.IP"\edi"
298300
List only indexes.
299-
.IP"\edt"
300-
Listonly tables.
301+
.IP"\edo"
302+
Listoperators.
301303
.IP"\eds"
302304
List only sequences.
305+
.IP"\edt"
306+
List only tables.
307+
.IP"\edT"
308+
List types.
303309
.IP"\ee [\fIfilename\fR]"
304310
Edit the current query buffer or\fIfile\fR.
305311
.IP"\eE [\fIfilename\fR]"

‎src/tools/backend/flow.gif

-651 KB
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp