psql \df option for procedures
psql's \df command current has options a/n/t/w to show
aggregates/normal/trigger/window functions. Do we want to add something
for procedures?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
"Peter" == Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
Peter> psql's \df command current has options a/n/t/w to show
Peter> aggregates/normal/trigger/window functions. Do we want to add
Peter> something for procedures?
yes
--
Andrew (irc:RhodiumToad)
On Mon, Jul 2, 2018 at 7:07 AM, Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> wrote:
psql's \df command current has options a/n/t/w to show
aggregates/normal/trigger/window functions. Do we want to add something
for procedures?
+1. I can write a patch to save your time If you don't do it yet.
Regards,
--
Fabrízio de Royes Mello Timbira - http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento
While you're looking at \df, you might want to consider removing the
display of source code (we have \sf for that, and it takes up a lot of
space), and add a column to display access permissions (who can execute the
function).
On 2 July 2018 at 09:22, Fabrízio de Royes Mello <fabriziomello@gmail.com>
wrote:
Show quoted text
On Mon, Jul 2, 2018 at 7:07 AM, Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> wrote:psql's \df command current has options a/n/t/w to show
aggregates/normal/trigger/window functions. Do we want to add something
for procedures?+1. I can write a patch to save your time If you don't do it yet.
Regards,
--
Fabrízio de Royes Mello Timbira - http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento
On 02.07.18 12:07, Peter Eisentraut wrote:
psql's \df command current has options a/n/t/w to show
aggregates/normal/trigger/window functions. Do we want to add something
for procedures?
Here is a patch.
The updated help string doesn't read particularly elegantly. Better ideas?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-psql-Add-option-for-procedures-to-df.patchtext/plain; charset=UTF-8; name=0001-psql-Add-option-for-procedures-to-df.patch; x-mac-creator=0; x-mac-type=0Download
From a95e93d4dc38d95868e0d114971165a6d53d0ce0 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Sat, 14 Jul 2018 12:17:49 +0200
Subject: [PATCH] psql: Add option for procedures to \df
---
doc/src/sgml/ref/psql-ref.sgml | 6 ++---
src/bin/psql/command.c | 1 +
src/bin/psql/describe.c | 43 ++++++++++++++++++++++++++++++----
src/bin/psql/help.c | 2 +-
4 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index b17039d60f..eb9d93a168 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1423,16 +1423,16 @@ <title>Meta-Commands</title>
<varlistentry>
- <term><literal>\df[antwS+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
+ <term><literal>\df[anptwS+] [ <link linkend="app-psql-patterns"><replaceable class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem>
<para>
Lists functions, together with their result data types, argument data
types, and function types, which are classified as <quote>agg</quote>
- (aggregate), <quote>normal</quote>, <quote>trigger</quote>, or <quote>window</quote>.
+ (aggregate), <quote>normal</quote>, <quote>procedure</quote>, <quote>trigger</quote>, or <quote>window</quote>.
To display only functions
of specific type(s), add the corresponding letters <literal>a</literal>,
- <literal>n</literal>, <literal>t</literal>, or <literal>w</literal> to the command.
+ <literal>n</literal>, <literal>p</literal>, <literal>t</literal>, or <literal>w</literal> to the command.
If <replaceable
class="parameter">pattern</replaceable> is specified, only
functions whose names match the pattern are shown.
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 4c85f43f09..f82f361fd8 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -754,6 +754,7 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
case 'S':
case 'a':
case 'n':
+ case 'p':
case 't':
case 'w':
success = describeFunctions(&cmd[2], pattern, show_verbose, show_system);
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 6e08515857..c0e79e0e8d 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -312,6 +312,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
{
bool showAggregate = strchr(functypes, 'a') != NULL;
bool showNormal = strchr(functypes, 'n') != NULL;
+ bool showProcedure = strchr(functypes, 'p') != NULL;
bool showTrigger = strchr(functypes, 't') != NULL;
bool showWindow = strchr(functypes, 'w') != NULL;
bool have_where;
@@ -323,9 +324,20 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
/* No "Parallel" column before 9.6 */
static const bool translate_columns_pre_96[] = {false, false, false, false, true, true, false, true, false, false, false, false};
- if (strlen(functypes) != strspn(functypes, "antwS+"))
+ if (strlen(functypes) != strspn(functypes, "anptwS+"))
{
- psql_error("\\df only takes [antwS+] as options\n");
+ psql_error("\\df only takes [anptwS+] as options\n");
+ return true;
+ }
+
+ if (showProcedure && pset.sversion < 110000)
+ {
+ char sverbuf[32];
+
+ psql_error("\\df does not take a \"%c\" option with server version %s\n",
+ 'p',
+ formatPGVersionNumber(pset.sversion, false,
+ sverbuf, sizeof(sverbuf)));
return true;
}
@@ -333,15 +345,18 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
{
char sverbuf[32];
- psql_error("\\df does not take a \"w\" option with server version %s\n",
+ psql_error("\\df does not take a \"%c\" option with server version %s\n",
+ 'w',
formatPGVersionNumber(pset.sversion, false,
sverbuf, sizeof(sverbuf)));
return true;
}
- if (!showAggregate && !showNormal && !showTrigger && !showWindow)
+ if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
{
showAggregate = showNormal = showTrigger = true;
+ if (pset.sversion >= 110000)
+ showProcedure = true;
if (pset.sversion >= 80400)
showWindow = true;
}
@@ -505,7 +520,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
have_where = false;
/* filter by function type, if requested */
- if (showNormal && showAggregate && showTrigger && showWindow)
+ if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
/* Do nothing */ ;
else if (showNormal)
{
@@ -523,6 +538,17 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
else
appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
}
+ if (!showProcedure && pset.sversion >= 110000)
+ {
+ if (have_where)
+ appendPQExpBufferStr(&buf, " AND ");
+ else
+ {
+ appendPQExpBufferStr(&buf, "WHERE ");
+ have_where = true;
+ }
+ appendPQExpBufferStr(&buf, "p.prokind <> 'p'\n");
+ }
if (!showTrigger)
{
if (have_where)
@@ -572,6 +598,13 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
"p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
needs_or = true;
}
+ if (showProcedure)
+ {
+ if (needs_or)
+ appendPQExpBufferStr(&buf, " OR ");
+ appendPQExpBufferStr(&buf, "p.prokind = 'p'\n");
+ needs_or = true;
+ }
if (showWindow)
{
if (needs_or)
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 702e742af4..316030d358 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -235,7 +235,7 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n"));
fprintf(output, _(" \\dew[+] [PATTERN] list foreign-data wrappers\n"));
- fprintf(output, _(" \\df[antw][S+] [PATRN] list [only agg/normal/trigger/window] functions\n"));
+ fprintf(output, _(" \\df[anptw][S+] [PATRN] list [only agg/normal/procedures/trigger/window] functions\n"));
fprintf(output, _(" \\dF[+] [PATTERN] list text search configurations\n"));
fprintf(output, _(" \\dFd[+] [PATTERN] list text search dictionaries\n"));
fprintf(output, _(" \\dFp[+] [PATTERN] list text search parsers\n"));
--
2.18.0
On 14.07.18 12:20, Peter Eisentraut wrote:
On 02.07.18 12:07, Peter Eisentraut wrote:
psql's \df command current has options a/n/t/w to show
aggregates/normal/trigger/window functions. Do we want to add something
for procedures?Here is a patch.
committed
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services