Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4e9df15

Browse files
committed
Add new \df psql option and oid8types() function.
1 parent 2e0976e commit 4e9df15

File tree

5 files changed

+101
-6
lines changed

5 files changed

+101
-6
lines changed

src/backend/utils/adt/regproc.c

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.8 1997/10/25 01:10:45 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.9 1997/11/15 16:32:01 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -118,7 +118,7 @@ regprocout(RegProcedure proid)
118118
if (!HeapScanIsValid(procscan))
119119
{
120120
heap_close(proc);
121-
elog(WARN, "regprocin: could not being scan of %s",
121+
elog(WARN, "regprocout: could not being scan of %s",
122122
ProcedureRelationName);
123123
return (0);
124124
}
@@ -150,6 +150,81 @@ regprocout(RegProcedure proid)
150150
return (result);
151151
}
152152

153+
/*
154+
* int8typeout - converts int8 type oids to "typname" list
155+
*/
156+
text *
157+
oid8types(Oid (*oidArray)[])
158+
{
159+
Relation type;
160+
HeapScanDesc typescan;
161+
HeapTuple typetup;
162+
text *result;
163+
ScanKeyData key;
164+
register int num;
165+
register Oid *sp;
166+
167+
if (oidArray == NULL)
168+
{
169+
result = (text *) palloc(VARHDRSZ);
170+
VARSIZE(result) = 0;
171+
return (result);
172+
}
173+
174+
result = (text *) palloc(NAMEDATALEN * 8 + 8 + VARHDRSZ);
175+
*VARDATA(result) = '\0';
176+
type = heap_openr(TypeRelationName);
177+
if (!RelationIsValid(type))
178+
{
179+
elog(WARN, "int8typeout: could not open %s",
180+
TypeRelationName);
181+
return (0);
182+
}
183+
184+
sp = *oidArray;
185+
for (num = 8; num != 0; num--, sp++)
186+
{
187+
if (*sp != InvalidOid)
188+
{
189+
ScanKeyEntryInitialize(&key,
190+
(bits16) 0,
191+
(AttrNumber) ObjectIdAttributeNumber,
192+
(RegProcedure) F_INT4EQ,
193+
(Datum) *sp);
194+
195+
typescan = heap_beginscan(type, 0, NowTimeQual, 1, &key);
196+
if (!HeapScanIsValid(typescan))
197+
{
198+
heap_close(type);
199+
elog(WARN, "int8typeout: could not being scan of %s",
200+
TypeRelationName);
201+
return (0);
202+
}
203+
typetup = heap_getnext(typescan, 0, (Buffer *) NULL);
204+
if (HeapTupleIsValid(typetup))
205+
{
206+
char *s;
207+
bool isnull;
208+
209+
s = (char *) heap_getattr(typetup, InvalidBuffer, 1,
210+
RelationGetTupleDescriptor(type), &isnull);
211+
if (!isnull)
212+
{
213+
StrNCpy(VARDATA(result)+strlen(VARDATA(result)),s,16);
214+
strcat(VARDATA(result)," ");
215+
}
216+
else
217+
elog(FATAL, "int8typeout: null procedure %d", *sp);
218+
/* FALLTHROUGH */
219+
}
220+
heap_endscan(typescan);
221+
}
222+
}
223+
heap_close(type);
224+
VARSIZE(result) = strlen(VARDATA(result)) + VARHDRSZ;
225+
return (result);
226+
}
227+
153228

154229
/*****************************************************************************
155230
* PUBLIC ROUTINES *

src/bin/psql/psql.c

Lines changed: 16 additions & 1 deletion
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.105 1997/11/14 21:37:41 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.106 1997/11/15 16:32:03 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -219,6 +219,7 @@ slashUsage(PsqlSettings *pset)
219219
fprintf(fout, " \\d [<table>] -- list tables and indices, columns in <table>, or * for all\n");
220220
fprintf(fout, " \\da -- list aggregates\n");
221221
fprintf(fout, " \\dd [<object>]- list comment for table, field, type, function, or operator.\n");
222+
fprintf(fout, " \\df -- list functions\n");
222223
fprintf(fout, " \\di -- list only indices\n");
223224
fprintf(fout, " \\do -- list operators\n");
224225
fprintf(fout, " \\ds -- list only sequences\n");
@@ -1691,6 +1692,20 @@ HandleSlashCmds(PsqlSettings *pset,
16911692
else if (strncmp(cmd, "dd", 2) == 0)
16921693
/* descriptions */
16931694
objectDescription(pset, optarg+1, NULL);
1695+
else if (strncmp(cmd, "df", 2) == 0)
1696+
/* functions/procedures */
1697+
/* we skip in/out funcs by excluding functions that take
1698+
some arguments, but have no types defined for those arguments */
1699+
SendQuery(&success, pset,"\
1700+
SELECT p.proname as function, \
1701+
t.typname as return_type, \
1702+
oid8types(p.proargtypes) as arguments, \
1703+
obj_description(p.oid) \
1704+
FROM pg_proc p, pg_type t \
1705+
WHERE p.prorettype = t.oid and \
1706+
(pronargs = 0 or oid8types(p.proargtypes) != '') \
1707+
ORDER BY function;",
1708+
false, false, 0);
16941709
else if (strncmp(cmd, "di", 2) == 0)
16951710
/* only indices */
16961711
tableList(pset, false, 'i');

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.35 1997/11/14 21:37:54 momjian Exp $
9+
* $Id: pg_proc.h,v 1.36 1997/11/15 16:32:09 momjian Exp $
1010
*
1111
* NOTES
1212
* The script catalog/genbki.sh reads this file and generates .bki
@@ -1651,6 +1651,8 @@ DATA(insert OID = 1347 ( int4 PGUID 14 f t f 1 f 23 "25" 100 0 0 100 "sele
16511651
DESCR("");
16521652
DATA(insert OID = 1348 ( obj_description PGUID 14 f t f 1 f 25 "26" 100 0 0 100 "select description from pg_description where objoid = $1" - ));
16531653
DESCR("");
1654+
DATA(insert OID = 1349 ( oid8types PGUID 11 f t f 1 f 25 "30" 100 0 0 100 foo bar ));
1655+
DESCR("");
16541656

16551657
DATA(insert OID = 1350 ( datetime PGUID 14 f t f 1 f 1184 "1184" 100 0 0 100 "select $1" - ));
16561658
DESCR("");

src/include/utils/builtins.h

Lines changed: 2 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: builtins.h,v 1.29 1997/10/30 16:42:50 thomas Exp $
9+
* $Id: builtins.h,v 1.30 1997/11/15 16:32:15 momjian Exp $
1010
*
1111
* NOTES
1212
* This should normally only be included by fmgr.h.
@@ -410,6 +410,7 @@ extern bool texticregexne(struct varlena * s, struct varlena * p);
410410
/* regproc.c */
411411
extern int32 regprocin(char *proname);
412412
extern char *regprocout(RegProcedure proid);
413+
extern text *oid8types(Oid (*oidArray)[]);
413414
extern Oid regproctooid(RegProcedure rp);
414415

415416
/* define macro to replace mixed-case function call - tgl 97/04/27 */

src/man/psql.1

Lines changed: 3 additions & 1 deletion
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.16 1997/11/15 02:47:23 thomas Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.17 1997/11/15 16:32:25 momjian Exp $
44
.TH PSQL UNIX 1/20/96 PostgreSQL PostgreSQL
55
.SH NAME
66
psql \(em run the interactive query front-end
@@ -296,6 +296,8 @@ list all tables and column information for each tables.
296296
List aggregates.
297297
.IP "\edd object"
298298
List the description of the table, table.column, type, operator, or aggregate.
299+
.IP "\edf"
300+
List functions.
299301
.IP "\edi"
300302
List only indexes.
301303
.IP "\edo"

0 commit comments

Comments
 (0)