On Tue, Apr 07, 2009 at 07:28:25PM -0700, David Fetter wrote:
> On Mon, Apr 06, 2009 at 10:51:22PM -0700, David Fetter wrote:
> > On Sun, Apr 05, 2009 at 05:57:46PM -0700, David Fetter wrote:
> > > On Sun, Apr 05, 2009 at 08:55:07PM -0400, Tom Lane wrote:
> > > > David Fetter <da...@fetter.org> writes:
> > > > > On Sun, Apr 05, 2009 at 02:07:32PM -0400, Tom Lane wrote:
> > > > >> The \df thing?  That's something it'd be okay to revisit during
> > > > >> beta, IMHO.
> > > > 
> > > > > OK, I'll work on this tomorrow :)
> > > > 
> > > > I think what we were lacking was consensus on what it should do, not
> > > > code ...
> > > 
> > > I was thinking I'd knock out a proposal or two.
> > 
> > Please find enclosed one way to handle it, this being prepending
> > WINDOW to the result types in \df.
> > 
> > Another way, patch coming tomorrow, would be to add a \dw and remove
> > the functions where pg_proc.iswindowing is true from \df.
> 
> Here's another way, adding \dw.

Revised patch attached.  \dw does not need an 'S' decorator, and would
be confusing with one now as there are only a few windowing functions,
and all of those system.

Also included are SGML docs.  Mea culpa.

There is one translatable string added.  Sorry about that.

Cheers,
David.
-- 
David Fetter <da...@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fet...@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 10d42ca..2e6484f 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1257,6 +1257,18 @@ testdb=&gt;
 
 
       <varlistentry>
+        <term><literal>\dw [ <replaceable 
class="parameter">pattern</replaceable> ]</literal></term>
+        <listitem>
+        <para>
+        Lists all windowing functions. If <replaceable
+        class="parameter">pattern</replaceable> is specified, only
+        those windowing functions whose names match the pattern are listed.
+        </para>
+        </listitem>
+      </varlistentry>
+
+
+      <varlistentry>
         <term><literal>\edit</literal> (or <literal>\e</literal>) 
<literal><optional> <replaceable class="parameter">filename</replaceable> 
</optional></literal></term>
 
         <listitem>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index b39466d..b737daf 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -396,6 +396,9 @@ exec_command(const char *cmd,
                        case 'u':
                                success = describeRoles(pattern, show_verbose);
                                break;
+                       case 'w':
+                               success = describeWindowingFunctions(pattern);
+                               break;
                        case 'F':                       /* text search 
subsystem */
                                switch (cmd[2])
                                {
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 731baf8..5699e29 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -280,6 +280,9 @@ describeFunctions(const char *pattern, bool verbose, bool 
showSystem)
                appendPQExpBuffer(&buf, "      AND n.nspname <> 'pg_catalog'\n"
                                                                "      AND 
n.nspname <> 'information_schema'\n");
 
+    if (pset.sversion >= 80400)
+               appendPQExpBuffer(&buf, "      AND NOT p.proiswindow\n");
+
        processSQLNamePattern(pset.db, &buf, pattern, true, false,
                                                  "n.nspname", "p.proname", 
NULL,
                                                  
"pg_catalog.pg_function_is_visible(p.oid)");
@@ -3059,6 +3062,56 @@ listUserMappings(const char *pattern, bool verbose)
        return true;
 }
 
+bool
+describeWindowingFunctions(const char *pattern)
+{
+       PQExpBufferData buf;
+       PGresult   *res;
+       printQueryOpt myopt = pset.popt;
+
+       if (pset.sversion < 80400)
+       {
+               fprintf(stderr, _("The server (version %d.%d) does not support 
windowing functions.\n"),
+                               pset.sversion / 10000, (pset.sversion / 100) % 
100);
+               return true;
+       }
+
+       initPQExpBuffer(&buf);
+
+       printfPQExpBuffer(&buf,
+                                         "SELECT n.nspname as \"%s\",\n"
+                                         "  p.proname as \"%s\",\n"
+                                         "  
pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
+                                         "  
pg_catalog.pg_get_function_arguments(p.oid) as \"%s\""
+                                         "\nFROM pg_catalog.pg_proc p"
+                                         "\n     LEFT JOIN 
pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
+                                         "WHERE p.proiswindow\n",
+                                         gettext_noop("Schema"),
+                                         gettext_noop("Name"),
+                                         gettext_noop("Result data type"),
+                                         gettext_noop("Argument data types"));
+
+       processSQLNamePattern(pset.db, &buf, pattern, true, false,
+                                                 "n.nspname", "p.proname", 
NULL,
+                                                 
"pg_catalog.pg_function_is_visible(p.oid)");
+
+       appendPQExpBuffer(&buf, "ORDER BY 1, 2, 4;");
+
+       res = PSQLexec(buf.data, false);
+       termPQExpBuffer(&buf);
+       if (!res)
+               return false;
+
+       myopt.nullPrint = NULL;
+       myopt.title = _("List of windowing functions");
+       myopt.translate_header = true;
+
+       printQuery(res, &myopt, pset.queryFout, pset.logfile);
+
+       PQclear(res);
+       return true;
+}
+
 /*
  * printACLColumn
  *
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 57e5c7b..3cad080 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -75,5 +75,8 @@ extern bool listForeignServers(const char *pattern, bool 
verbose);
 /* \deu */
 extern bool listUserMappings(const char *pattern, bool verbose);
 
+/* \dw */
+extern bool describeWindowingFunctions(const char *pattern);
+
 
 #endif   /* DESCRIBE_H */
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 389feb0..494d42f 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -221,6 +221,7 @@ slashUsage(unsigned short int pager)
        fprintf(output, _("  \\dT[S+] [PATTERN]      list data types\n"));
        fprintf(output, _("  \\du     [PATTERN]      list roles (users)\n"));
        fprintf(output, _("  \\dv[S+] [PATTERN]      list views\n"));
+       fprintf(output, _("  \\dw     [PATTERN]      list windowing 
functions\n"));
        fprintf(output, _("  \\l[+]                  list all databases\n"));
        fprintf(output, _("  \\z      [PATTERN]      same as \\dp\n"));
        fprintf(output, "\n");
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to