Apply the proper version of Christopher Kings-Lynne's describe patch
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 7 Jan 2003 20:56:07 +0000 (20:56 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 7 Jan 2003 20:56:07 +0000 (20:56 +0000)
(ie, the one with describe-schema support).  Minor code review.
Adjust display of casts to use standard type names.

doc/src/sgml/ref/psql-ref.sgml
src/backend/catalog/namespace.c
src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/describe.h
src/bin/psql/help.c
src/include/catalog/namespace.h

index 77da336696a20ca682f9777e6099f72339f660bf..677b4773b43d11abb8bc99fcc6b8fb3fcc5f4015 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.83 2003/01/07 18:46:52 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.84 2003/01/07 20:56:06 tgl Exp $
 PostgreSQL documentation
 -->
 
@@ -798,6 +798,30 @@ testdb=>
         </listitem>
       </varlistentry>
 
+
+      <varlistentry>
+        <term><literal>\dc</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
+        <listitem>
+        <para>
+        Lists all available conversions between character-set encodings.
+   If <replaceable class="parameter">pattern</replaceable>
+        is specified, only conversions whose name matches the pattern are
+   listed.
+        </para>
+        </listitem>
+      </varlistentry>
+
+
+      <varlistentry>
+        <term><literal>\dC</literal></term>
+        <listitem>
+        <para>
+        Lists all available type casts.
+        </para>
+        </listitem>
+      </varlistentry>
+
+
       <varlistentry>
         <term><literal>\dd</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
         <listitem>
@@ -847,29 +871,6 @@ testdb=>
       </varlistentry>
 
 
-      <varlistentry>
-        <term><literal>\dc</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
-        <listitem>
-        <para>
-        Lists all available conversions (between encodings). If <replaceable
-        class="parameter">pattern</replaceable>
-        is specified, only matching conversions are shown.
-        </para>
-        </listitem>
-      </varlistentry>
-
-
-      <varlistentry>
-        <term><literal>\dC</literal></term>
-        <listitem>
-        <para>
-        Lists all available type casts.  Casts can be explicit, explicit and assignment
-   or implicit, and are used to change a variable from one type to another.
-        </para>
-        </listitem>
-      </varlistentry>
-
-
       <varlistentry>
         <term><literal>\df [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
 
@@ -929,6 +930,19 @@ testdb=>
       </varlistentry>
 
 
+      <varlistentry>
+        <term><literal>\dn</literal> [ <replaceable class="parameter">pattern</replaceable> ]</term>
+
+        <listitem>
+        <para>
+        Lists all available schemas (namespaces). If <replaceable
+        class="parameter">pattern</replaceable> (a regular expression)
+        is specified, only schemas whose name matches the pattern are listed.
+        </para>
+        </listitem>
+      </varlistentry>
+
+
       <varlistentry>
         <term><literal>\do [ <replaceable class="parameter">pattern</replaceable> ]</literal></term>
         <listitem>
@@ -1054,8 +1068,9 @@ Tue Oct 26 21:40:57 CEST 1999
         </para>
    <note>
    <para>
-   This command does not see changes made by <command>SET
-        CLIENT_ENCODING</>.
+   This command will not notice changes made directly by <command>SET
+        CLIENT_ENCODING</>.  If you use <literal>\encoding</literal>,
+   be sure to use it to set as well as examine the encoding.
    </para>
    </note> 
         </listitem>
index fa0d20af307da781da711944fb9e5b6675a02888..0c571ca2a4028ef7dd7a53bcd6e47f1da1709864 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.42 2002/12/12 21:02:19 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.43 2003/01/07 20:56:06 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -145,6 +145,7 @@ Datum       pg_operator_is_visible(PG_FUNCTION_ARGS);
 Datum      pg_opclass_is_visible(PG_FUNCTION_ARGS);
 Datum      pg_conversion_is_visible(PG_FUNCTION_ARGS);
 
+
 /*
  * RangeVarGetRelid
  *     Given a RangeVar describing an existing relation,
@@ -1084,7 +1085,7 @@ ConversionIsVisible(Oid conid)
                            ObjectIdGetDatum(conid),
                            0, 0, 0);
    if (!HeapTupleIsValid(contup))
-       elog(ERROR, "Cache lookup failed for converions %u", conid);
+       elog(ERROR, "Cache lookup failed for conversion %u", conid);
    conform = (Form_pg_conversion) GETSTRUCT(contup);
 
    recomputeNamespacePath();
@@ -1104,7 +1105,7 @@ ConversionIsVisible(Oid conid)
         * If it is in the path, it might still not be visible; it could
         * be hidden by another conversion of the same name earlier in the
         * path. So we must do a slow check to see if this conversion would
-        * be found by ConvnameGetConid.
+        * be found by ConversionGetConid.
         */
        char       *conname = NameStr(conform->conname);
        
index 06d31598566207bd8883216979a8e30c61ec7fb5..419e44a63265418fd1be57a5d776775744709de6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.86 2002/12/12 21:02:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.87 2003/01/07 20:56:06 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -350,15 +350,27 @@ exec_command(const char *cmd,
            case 'a':
                success = describeAggregates(pattern, show_verbose);
                break;
+           case 'c':
+               success = listConversions(pattern);
+               break;
+           case 'C':
+               success = listCasts(pattern);
+               break;
            case 'd':
                success = objectDescription(pattern);
                break;
+           case 'D':
+               success = listDomains(pattern);
+               break;
            case 'f':
                success = describeFunctions(pattern, show_verbose);
                break;
            case 'l':
                success = do_lo_list();
                break;
+           case 'n':
+               success = listSchemas(pattern);
+               break;
            case 'o':
                success = describeOperators(pattern);
                break;
@@ -378,16 +390,7 @@ exec_command(const char *cmd,
            case 'u':
                success = describeUsers(pattern);
                break;
-           case 'D':
-               success = listDomains(pattern);
-               break;
-           case 'c':
-               success = listConversions(pattern);
-               break;
-           case 'C':
-               success = listCasts(pattern);
-               break;
-               
+
            default:
                status = CMD_UNKNOWN;
        }
index d4f7e1ededd2f065b42059451faeb91ddcba176c..0614b63da8dbe3c74dd5fa8ce1f3e23bc40d9e4e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.73 2002/12/21 01:07:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.74 2003/01/07 20:56:06 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "describe.h"
@@ -1426,15 +1426,16 @@ listConversions(const char *pattern)
                      "       pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
                      "       pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
                      "       CASE WHEN c.condefault THEN '%s'\n"
-                     "       ELSE NULL END AS \"%s\"\n"
+                     "       ELSE '%s' END AS \"%s\"\n"
                      "FROM pg_catalog.pg_conversion c, pg_catalog.pg_namespace n\n"
                      "WHERE n.oid = c.connamespace\n",
                      _("Schema"),
                      _("Name"),
                      _("Source"),
-                     _("Dest"),
-                     _("default"),
-                     _("Modifier"));
+                     _("Destination"),
+                     _("yes"),
+                     _("no"),
+                     _("Default?"));
 
    processNamePattern(&buf, pattern, true, false,
                       "n.nspname", "c.conname", NULL,
@@ -1471,9 +1472,9 @@ listCasts(const char *pattern)
    initPQExpBuffer(&buf);
 /* NEED LEFT JOIN FOR BINARY CASTS */
    printfPQExpBuffer(&buf,
-                     "SELECT t1.typname AS \"%s\",\n"
-                     "       t2.typname AS \"%s\",\n"
-                     "       CASE WHEN p.proname IS NULL THEN '%s'\n"
+                     "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
+                     "       pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
+                     "       CASE WHEN castfunc = 0 THEN '%s'\n"
                      "            ELSE p.proname\n"
                      "       END as \"%s\",\n"
                      "       CASE WHEN c.castcontext = 'e' THEN '%s'\n"
@@ -1481,16 +1482,16 @@ listCasts(const char *pattern)
                      "            ELSE '%s'\n"
                      "       END as \"%s\"\n"
                      "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
-                     "       ON c.castfunc=p.oid, pg_catalog.pg_type t1, pg_catalog.pg_type t2\n"
-                     "WHERE c.castsource=t1.oid AND c.casttarget=t2.oid ORDER BY 1, 2",
+                     "     ON c.castfunc = p.oid\n"
+                     "ORDER BY 1, 2",
                      _("Source"),
                      _("Target"),
                      _("BINARY"),
                      _("Function"),
-                     _("explicit"),
-                     _("assignment explicit"),
-                     _("implicit"),
-                     _("Context"));
+                     _("no"),
+                     _("in assignment"),
+                     _("yes"),
+                     _("Implicit?"));
 
    res = PSQLexec(buf.data, false);
    termPQExpBuffer(&buf);
@@ -1506,6 +1507,48 @@ listCasts(const char *pattern)
    return true;
 }
 
+/*
+ * \dn
+ *
+ * Describes schemas (namespaces)
+ */
+bool
+listSchemas(const char *pattern)
+{
+   PQExpBufferData buf;
+   PGresult   *res;
+   printQueryOpt myopt = pset.popt;
+
+   initPQExpBuffer(&buf);
+   printfPQExpBuffer(&buf,
+                     "SELECT n.nspname AS \"%s\",\n"
+                     "       u.usename AS \"%s\"\n"
+                     "FROM pg_catalog.pg_namespace n LEFT JOIN pg_catalog.pg_user u\n"
+                     "       ON n.nspowner=u.usesysid\n",
+                     _("Name"),
+                     _("Owner"));
+
+   processNamePattern(&buf, pattern, false, false,
+                      NULL, "n.nspname", NULL,
+                      NULL);
+
+   appendPQExpBuffer(&buf, "ORDER BY 1;");
+
+   res = PSQLexec(buf.data, false);
+   termPQExpBuffer(&buf);
+   if (!res)
+       return false;
+
+   myopt.nullPrint = NULL;
+   myopt.title = _("List of schemas");
+
+   printQuery(res, &myopt, pset.queryFout);
+
+   PQclear(res);
+   return true;
+}
+
+
 /*
  * processNamePattern
  *
index 6461b41d303c311628728d7d6de96fae025c8b7c..40a94b0efd21de1d01ff711d7e8dcf41667bf68a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.19 2002/12/12 21:02:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.h,v 1.20 2003/01/07 20:56:07 tgl Exp $
  */
 #ifndef DESCRIBE_H
 #define DESCRIBE_H
@@ -49,5 +49,8 @@ bool      listConversions(const char *pattern);
 /* \dC */
 bool       listCasts(const char *pattern);
 
+/* \dn */
+bool       listSchemas(const char *pattern);
+
 
 #endif   /* DESCRIBE_H */
index e921f1da4b8e61ae4aee1c540ecdb0dcb7e0a6e9..2dcf798d9dd6b8c68680bed4b78aa594ed62c1b7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.68 2002/12/13 22:17:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.69 2003/01/07 20:56:07 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -211,6 +211,7 @@ slashUsage(unsigned short int pager)
    fprintf(output, _("  \\dd [PATTERN]  show comment for object\n"));
    fprintf(output, _("  \\dD [PATTERN]  list domains\n"));
    fprintf(output, _("  \\df [PATTERN]  list functions (add \"+\" for more detail)\n"));
+   fprintf(output, _("  \\dn [PATTERN]  list schemas\n"));
    fprintf(output, _("  \\do [NAME]     list operators\n"));
    fprintf(output, _("  \\dl            list large objects, same as \\lo_list\n"));
    fprintf(output, _("  \\dp [PATTERN]  list table access privileges\n"));
index 27e3e75168f861c5aaafd9aabc7c7b598e6bf712..8bcd48767083edf20eb8a1903ca1456513a83d26 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: namespace.h,v 1.23 2002/12/12 21:02:25 momjian Exp $
+ * $Id: namespace.h,v 1.24 2003/01/07 20:56:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -65,8 +65,9 @@ extern bool OperatorIsVisible(Oid oprid);
 extern OpclassCandidateList OpclassGetCandidates(Oid amid);
 extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname);
 extern bool OpclassIsVisible(Oid opcid);
-extern bool ConversionIsVisible(Oid opcid);
+
 extern Oid ConversionGetConid(const char *conname);
+extern bool ConversionIsVisible(Oid conid);
 
 extern void DeconstructQualifiedName(List *names,
                         char **nspname_p,