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

Commitaeb3c2f

Browse files
committed
Add agg/normal/trigger/window flags for psql \df and in \df output.
David Fetter
1 parent02dec25 commitaeb3c2f

File tree

6 files changed

+163
-38
lines changed

6 files changed

+163
-38
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.223 2009/04/08 22:29:30 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.224 2009/04/21 15:49:06 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1039,18 +1039,22 @@ testdb=&gt;
10391039

10401040
<varlistentry>
10411041
<term><literal>\df[S+] [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
1042+
<term><literal>\df[antw][S+] [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
10421043

10431044
<listitem>
10441045
<para>
1045-
Lists available functions, together with their argument and
1046-
return types. If <replaceable
1047-
class="parameter">pattern</replaceable>
1048-
is specified, only functions whose names match the pattern are shown.
1049-
If the form <literal>\df+</literal> is used, additional information about
1050-
each function, including volatility, language, source code and description, is shown.
1051-
By default, only user-created objects are shown; supply a
1052-
pattern or the <literal>S</literal> modifier to include system
1053-
objects.
1046+
Lists available functions, together with their arguments,
1047+
return types, and their function types: 'agg' (aggregate),
1048+
'normal', 'trigger', and 'window'. To display only functions
1049+
of a specific type, use the corresponding letters <literal>a</>,
1050+
<literal>n</>, <literal>t</>, or <literal>w</>. If <replaceable
1051+
class="parameter">pattern</replaceable> is specified, only
1052+
functions whose names match the pattern are shown. If the
1053+
form <literal>\df+</literal> is used, additional information
1054+
about each function, including volatility, language, source
1055+
code and description, is shown. By default, only user-created
1056+
objects are shown; supply a pattern or the <literal>S</literal>
1057+
modifier to include system objects.
10541058
</para>
10551059

10561060
<note>
@@ -1064,7 +1068,6 @@ testdb=&gt;
10641068
</listitem>
10651069
</varlistentry>
10661070

1067-
10681071
<varlistentry>
10691072
<term><literal>\dF[+] [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
10701073
<listitem>

‎src/bin/psql/command.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.204 2009/03/25 13:07:26 petere Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.205 2009/04/21 15:49:06 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -365,8 +365,22 @@ exec_command(const char *cmd,
365365
case'D':
366366
success=listDomains(pattern,show_system);
367367
break;
368-
case'f':
369-
success=describeFunctions(pattern,show_verbose,show_system);
368+
case'f':/* function subsystem */
369+
switch (cmd[2])
370+
{
371+
case'\0':
372+
case'+':
373+
case'S':
374+
case'a':
375+
case'n':
376+
case't':
377+
case'w':
378+
success=describeFunctions(&cmd[2],pattern,show_verbose,show_system);
379+
break;
380+
default:
381+
status=PSQL_CMD_UNKNOWN;
382+
break;
383+
}
370384
break;
371385
case'g':
372386
/* no longer distinct from \du */

‎src/bin/psql/describe.c

Lines changed: 120 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
1010
*
11-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.208 2009/04/08 22:29:30 tgl Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.209 2009/04/21 15:49:06 momjian Exp $
1212
*/
1313
#include"postgres_fe.h"
1414

@@ -183,15 +183,43 @@ describeTablespaces(const char *pattern, bool verbose)
183183

184184

185185
/* \df
186-
* Takes an optional regexp to select particular functions
186+
* Takes an optional regexp to select particular functions.
187+
*
188+
* As with \d, you can specify the kinds of functions you want:
189+
*
190+
* a for aggregates
191+
* n for normal
192+
* t for trigger
193+
* w for window
194+
*
195+
* and you can mix and match these in any order.
187196
*/
188197
bool
189-
describeFunctions(constchar*pattern,boolverbose,boolshowSystem)
198+
describeFunctions(constchar*functypes,constchar*pattern,boolverbose,boolshowSystem)
190199
{
200+
boolshowAggregate=strchr(functypes,'a')!=NULL;
201+
boolshowNormal=strchr(functypes,'n')!=NULL;
202+
boolshowTrigger=strchr(functypes,'t')!=NULL;
203+
boolshowWindow=strchr(functypes,'w')!=NULL;
204+
191205
PQExpBufferDatabuf;
192206
PGresult*res;
193207
printQueryOptmyopt=pset.popt;
194208

209+
if (showWindow&&pset.sversion<80400)
210+
{
211+
fprintf(stderr,_("\\df does not take a \"w\" decorator in %d.%d.\n"),
212+
pset.sversion /10000, (pset.sversion /100) %100);
213+
return true;
214+
}
215+
216+
if (!showAggregate&& !showNormal&& !showTrigger&& !showWindow)
217+
{
218+
showAggregate=showNormal=showTrigger= true;
219+
if (pset.sversion >=80400)
220+
showWindow= true;
221+
}
222+
195223
initPQExpBuffer(&buf);
196224

197225
printfPQExpBuffer(&buf,
@@ -203,9 +231,21 @@ describeFunctions(const char *pattern, bool verbose, bool showSystem)
203231
if (pset.sversion >=80400)
204232
appendPQExpBuffer(&buf,
205233
" pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
206-
" pg_catalog.pg_get_function_arguments(p.oid) as \"%s\"",
234+
" pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
235+
" CASE\n"
236+
" WHEN p.proisagg THEN '%s'\n"
237+
" WHEN p.proiswindow THEN '%s'\n"
238+
" WHEN pg_catalog.pg_get_function_result(p.oid) = 'trigger' THEN '%s'\n"
239+
" ELSE '%s'\n"
240+
"END as \"%s\"",
207241
gettext_noop("Result data type"),
208-
gettext_noop("Argument data types"));
242+
gettext_noop("Argument data types"),
243+
/* translator: "agg" is short for "aggregate" */
244+
gettext_noop("agg"),
245+
gettext_noop("window"),
246+
gettext_noop("trigger"),
247+
gettext_noop("normal"),
248+
gettext_noop("Type"));
209249
elseif (pset.sversion >=80100)
210250
appendPQExpBuffer(&buf,
211251
" CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
@@ -238,16 +278,36 @@ describeFunctions(const char *pattern, bool verbose, bool showSystem)
238278
" FROM\n"
239279
" pg_catalog.generate_series(0, pg_catalog.array_upper(p.proargtypes, 1)) AS s(i)\n"
240280
" ), ', ')\n"
281+
" END AS \"%s\",\n"
282+
" CASE\n"
283+
" WHEN p.proisagg THEN '%s'\n"
284+
" WHEN 'trigger' = pg_catalog.format_type(p.prorettype, NULL) THEN '%s'\n"
285+
" ELSE '%s'\n"
241286
" END AS \"%s\"",
242287
gettext_noop("Result data type"),
243-
gettext_noop("Argument data types"));
288+
gettext_noop("Argument data types"),
289+
/* translator: "agg" is short for "aggregate" */
290+
gettext_noop("agg"),
291+
gettext_noop("trigger"),
292+
gettext_noop("normal"),
293+
gettext_noop("Type"));
244294
else
245295
appendPQExpBuffer(&buf,
246296
" CASE WHEN p.proretset THEN 'SETOF ' ELSE '' END ||\n"
247297
" pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
248-
" pg_catalog.oidvectortypes(p.proargtypes) as \"%s\"",
298+
" pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
299+
" CASE\n"
300+
" WHEN p.proisagg THEN '%s'\n"
301+
" WHEN 'trigger' = pg_catalog.format_type(p.prorettype, NULL) THEN '%s'\n"
302+
" ELSE '%s'\n"
303+
" END AS \"%s\"",
249304
gettext_noop("Result data type"),
250-
gettext_noop("Argument data types"));
305+
gettext_noop("Argument data types"),
306+
/* translator: "agg" is short for "aggregate" */
307+
gettext_noop("agg"),
308+
gettext_noop("trigger"),
309+
gettext_noop("normal"),
310+
gettext_noop("Type"));
251311

252312
if (verbose)
253313
appendPQExpBuffer(&buf,
@@ -274,16 +334,63 @@ describeFunctions(const char *pattern, bool verbose, bool showSystem)
274334
appendPQExpBuffer(&buf,
275335
" LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
276336

277-
appendPQExpBuffer(&buf,"WHERE NOT p.proisagg\n");
337+
processSQLNamePattern(pset.db,&buf,pattern, false, true,
338+
"n.nspname","p.proname",NULL,
339+
"pg_catalog.pg_function_is_visible(p.oid)");
340+
341+
if (showNormal&&showAggregate&&showTrigger&&showWindow)
342+
/* Do nothing */;
343+
elseif (showNormal)
344+
{
345+
if (!showWindow&&pset.sversion >=80400)
346+
appendPQExpBuffer(&buf," AND NOT p.proiswindow\n");
347+
if (!showAggregate)
348+
appendPQExpBuffer(&buf," AND NOT p.proisagg\n");
349+
if (!showTrigger)
350+
{
351+
if (pset.sversion >=80400)
352+
appendPQExpBuffer(&buf,
353+
" AND pg_catalog.pg_get_function_result(p.oid) <> 'trigger'\n");
354+
else
355+
appendPQExpBuffer(&buf,
356+
" AND pg_catalog.format_type(p.prorettype, NULL) <> 'trigger'\n");
357+
}
358+
}
359+
else
360+
{
361+
boolneeds_or= false;
362+
363+
appendPQExpBuffer(&buf," AND (\n ");
364+
if (showAggregate)
365+
{
366+
appendPQExpBuffer(&buf,"p.proisagg\n");
367+
needs_or= true;
368+
}
369+
if (showTrigger)
370+
{
371+
if (needs_or)
372+
appendPQExpBuffer(&buf," OR ");
373+
if (pset.sversion >=80400)
374+
appendPQExpBuffer(&buf,
375+
"pg_catalog.pg_get_function_result(p.oid) = 'trigger'\n");
376+
else
377+
appendPQExpBuffer(&buf,
378+
"'trigger' <> pg_catalog.format_type(p.prorettype, NULL)\n");
379+
needs_or= true;
380+
}
381+
if (showWindow)
382+
{
383+
if (needs_or)
384+
appendPQExpBuffer(&buf," OR ");
385+
appendPQExpBuffer(&buf,"p.proiswindow\n");
386+
}
387+
appendPQExpBuffer(&buf," )\n");
388+
}
278389

279390
if (!showSystem&& !pattern)
280391
appendPQExpBuffer(&buf," AND n.nspname <> 'pg_catalog'\n"
281392
" AND n.nspname <> 'information_schema'\n");
282393

283-
processSQLNamePattern(pset.db,&buf,pattern, true, false,
284-
"n.nspname","p.proname",NULL,
285-
"pg_catalog.pg_function_is_visible(p.oid)");
286-
287394
appendPQExpBuffer(&buf,"ORDER BY 1, 2, 4;");
288395

289396
res=PSQLexec(buf.data, false);

‎src/bin/psql/describe.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.39 2009/01/20 02:13:42 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.h,v 1.40 2009/04/21 15:49:06 momjian Exp $
77
*/
88
#ifndefDESCRIBE_H
99
#defineDESCRIBE_H
@@ -15,8 +15,8 @@ extern bool describeAggregates(const char *pattern, bool verbose, bool showSyste
1515
/* \db */
1616
externbooldescribeTablespaces(constchar*pattern,boolverbose);
1717

18-
/* \df */
19-
externbooldescribeFunctions(constchar*pattern,boolverbose,boolshowSystem);
18+
/* \df, \dfa, \dfn, \dft, \dfw, etc. */
19+
externbooldescribeFunctions(constchar*functypes,constchar*pattern,boolverbose,boolshowSystem);
2020

2121
/* \dT */
2222
externbooldescribeTypes(constchar*pattern,boolverbose,boolshowSystem);

‎src/bin/psql/help.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.146 2009/04/11 14:11:21 petere Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.147 2009/04/21 15:49:06 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -196,7 +196,7 @@ slashUsage(unsigned short int pager)
196196
fprintf(output,_(" (options: S = show system objects, + = additional detail)\n"));
197197
fprintf(output,_(" \\d[S+] list tables, views, and sequences\n"));
198198
fprintf(output,_(" \\d[S+] NAME describe table, view, sequence, or index\n"));
199-
fprintf(output,_(" \\da[S] [PATTERN] listaggregate functions\n"));
199+
fprintf(output,_(" \\da[+] [PATTERN] listaggregates\n"));
200200
fprintf(output,_(" \\db[+] [PATTERN] list tablespaces\n"));
201201
fprintf(output,_(" \\dc[S] [PATTERN] list conversions\n"));
202202
fprintf(output,_(" \\dC [PATTERN] list casts\n"));
@@ -206,6 +206,7 @@ slashUsage(unsigned short int pager)
206206
fprintf(output,_(" \\deu[+] [PATTERN] list user mappings\n"));
207207
fprintf(output,_(" \\dew[+] [PATTERN] list foreign-data wrappers\n"));
208208
fprintf(output,_(" \\df[S+] [PATTERN] list functions\n"));
209+
fprintf(output,_(" \\df[antwS+] [PATTERN] list only agg/normal/trigger/window functions\n"));
209210
fprintf(output,_(" \\dF[+] [PATTERN] list text search configurations\n"));
210211
fprintf(output,_(" \\dFd[+] [PATTERN] list text search dictionaries\n"));
211212
fprintf(output,_(" \\dFp[+] [PATTERN] list text search parsers\n"));

‎src/test/regress/expected/polymorphism.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,9 @@ select dfunc();
838838
-- verify it lists properly
839839
\df dfunc
840840
List of functions
841-
Schema | Name | Result data type | Argument data types
842-
--------+-------+------------------+-----------------------------------------------------------
843-
public | dfunc | integer | a integer DEFAULT 1, OUT sum integer, b integer DEFAULT 2
841+
Schema | Name | Result data type | Argument data types| Type
842+
--------+-------+------------------+-----------------------------------------------------------+--------
843+
public | dfunc | integer | a integer DEFAULT 1, OUT sum integer, b integer DEFAULT 2 | normal
844844
(1 row)
845845

846846
drop function dfunc(int, int);
@@ -1006,9 +1006,9 @@ ERROR: cannot remove parameter defaults from existing function
10061006
HINT: Use DROP FUNCTION first.
10071007
\df dfunc
10081008
List of functions
1009-
Schema | Name | Result data type | Argument data types
1010-
--------+-------+------------------+-------------------------------------------------
1011-
public | dfunc | integer | VARIADIC a integer[] DEFAULT ARRAY[]::integer[]
1009+
Schema | Name | Result data type | Argument data types| Type
1010+
--------+-------+------------------+-------------------------------------------------+--------
1011+
public | dfunc | integer | VARIADIC a integer[] DEFAULT ARRAY[]::integer[] | normal
10121012
(1 row)
10131013

10141014
drop function dfunc(a variadic int[]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp