Fix minor issues in psql's new \dAc and related commands.
authorTom Lane
Sun, 2 Aug 2020 21:00:26 +0000 (17:00 -0400)
committerTom Lane
Sun, 2 Aug 2020 21:00:26 +0000 (17:00 -0400)
The type-name pattern in \dAc and \dAf was matched only to the actual
pg_type.typname string, which is fairly user-unfriendly in cases where
that is not what's shown to the user by format_type (compare "_int4"
and "integer[]").  Make this code match what \dT does, i.e. match the
pattern against either typname or format_type() output.  Also fix its
broken handling of schema-name restrictions.  (IOW, make these
processSQLNamePattern calls match \dT's.)  While here, adjust
whitespace to make the query a little prettier in -E output, too.

Also improve some inaccuracies and shaky grammar in the related
documentation.

Noted while working on a patch for intarray's opclasses; I wondered
why I couldn't get a match to "integer*" for the input type name.

doc/src/sgml/indices.sgml
doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/describe.c

index 28adaba72d0458a664a2ad390f3d712e2d7d6dea..671299ff059d972ff95bdb1d67ed4c89bf5040b2 100644 (file)
@@ -1410,6 +1410,15 @@ SELECT am.amname AS index_method,
     ORDER BY index_method, opfamily_name, opfamily_operator;
 
   
+
+  
+   
+     has
+    commands \dAc\dAf,
+    and \dAo, which provide slightly more sophisticated
+    versions of these queries.
+   
+  
  
 
 
index 13179e845da7047a55b93b5dfdf527be853b5968..fc16e6c0c41377ed0d983851d5d93d679d5c5ade 100644 (file)
@@ -1245,13 +1245,13 @@ testdb=>
         
         
         Lists operator classes
-        (see catalog-pg-opclass"/>).
+        (see xindex-opclass"/>).
         If access-method-pattern
         is specified, only operator classes associated with access methods whose
-        names match the pattern are listed.
+        names match that pattern are listed.
         If input-type-pattern
         is specified, only operator classes associated with input types whose
-        names match the pattern are listed.
+        names match that pattern are listed.
         If + is appended to the command name, each operator
         class is listed with its associated operator family and owner.
         
@@ -1268,13 +1268,13 @@ testdb=>
         
         
         Lists operator families
-        (see catalog-pg-opfamily"/>).
+        (see xindex-opfamily"/>).
         If access-method-pattern
         is specified, only operator families associated with access methods whose
-        names match the pattern are listed.
+        names match that pattern are listed.
         If input-type-pattern
         is specified, only operator families associated with input types whose
-        names match the pattern are listed.
+        names match that pattern are listed.
         If + is appended to the command name, each operator
         family is listed with its owner.
         
@@ -1292,15 +1292,15 @@ testdb=>
         
         
         Lists operators associated with operator families
-        ("/>).
+        (see "/>).
         If access-method-pattern
         is specified, only members of operator families associated with access
-        methods whose names match the pattern are listed.
-        If input-type-pattern
-        is specified, only members of operator families whose names match the
+        methods whose names match that pattern are listed.
+        If operator-family-pattern
+        is specified, only members of operator families whose names match that
         pattern are listed.
         If + is appended to the command name, each operator
-        is listed with its strategy number, purpose and sort operator family.
+        is listed with its sort operator family (if it is an ordering operator).
         
         
       
@@ -1314,14 +1314,16 @@ testdb=>
         
         
         
-        Lists functions associated with operator families
-        ("/>).
+        Lists support functions associated with operator families
+        (see "/>).
         If access-method-pattern
-        is specified, only members of operator families associated with access
-        methods whose names match the pattern are listed.
-        If input-type-pattern
-        is specified, only members of operator families whose names match the
-        pattern are listed.
+        is specified, only functions of operator families associated with
+        access methods whose names match that pattern are listed.
+        If operator-family-pattern
+        is specified, only functions of operator families whose names match
+        that pattern are listed.
+        If + is appended to the command name, functions are
+        displayed verbosely, with their actual parameter lists.
         
         
       
index 3b870c3b17e238c327d1b7ec3833f8c54c5e77bd..25d5b06de253c043147d1661e8457e5fdf6976e1 100644 (file)
@@ -6050,7 +6050,7 @@ printACLColumn(PQExpBuffer buf, const char *colname)
  * \dAc
  * Lists operator classes
  *
- * Takes an optional regexps to filter by index access method and type.
+ * Takes optional regexps to filter by index access method and input data type.
  */
 bool
 listOperatorClasses(const char *access_method_pattern,
@@ -6104,6 +6104,7 @@ listOperatorClasses(const char *access_method_pattern,
                      "  LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
                      "  LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
                      "  LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
+                     "  LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
        );
    if (verbose)
        appendPQExpBuffer(&buf,
@@ -6114,8 +6115,13 @@ listOperatorClasses(const char *access_method_pattern,
        have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
                                           false, false, NULL, "am.amname", NULL, NULL);
    if (type_pattern)
+   {
+       /* Match type name pattern against either internal or external name */
        processSQLNamePattern(pset.db, &buf, type_pattern, have_where, false,
-                             NULL, "t.typname", NULL, NULL);
+                             "tn.nspname", "t.typname",
+                             "pg_catalog.format_type(t.oid, NULL)",
+                             "pg_catalog.pg_type_is_visible(t.oid)");
+   }
 
    appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
    res = PSQLexec(buf.data);
@@ -6139,7 +6145,7 @@ listOperatorClasses(const char *access_method_pattern,
  * \dAf
  * Lists operator families
  *
- * Takes an optional regexps to filter by index access method and type.
+ * Takes optional regexps to filter by index access method and input data type.
  */
 bool
 listOperatorFamilies(const char *access_method_pattern,
@@ -6184,15 +6190,19 @@ listOperatorFamilies(const char *access_method_pattern,
    if (type_pattern)
    {
        appendPQExpBuffer(&buf,
-                         "\n  %s EXISTS (\n"
+                         "  %s EXISTS (\n"
                          "    SELECT 1\n"
                          "    FROM pg_catalog.pg_type t\n"
                          "    JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
-                         "    WHERE oc.opcfamily = f.oid",
+                         "    LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
+                         "    WHERE oc.opcfamily = f.oid\n",
                          have_where ? "AND" : "WHERE");
+       /* Match type name pattern against either internal or external name */
        processSQLNamePattern(pset.db, &buf, type_pattern, true, false,
-                             NULL, "t.typname", NULL, NULL);
-       appendPQExpBuffer(&buf, ")");
+                             "tn.nspname", "t.typname",
+                             "pg_catalog.format_type(t.oid, NULL)",
+                             "pg_catalog.pg_type_is_visible(t.oid)");
+       appendPQExpBuffer(&buf, "  )\n");
    }
 
    appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
@@ -6217,7 +6227,7 @@ listOperatorFamilies(const char *access_method_pattern,
  * \dAo
  * Lists operators of operator families
  *
- * Takes an optional regexps to filter by index access method and operator
+ * Takes optional regexps to filter by index access method and operator
  * family.
  */
 bool
@@ -6304,7 +6314,7 @@ listOpFamilyOperators(const char *access_method_pattern,
  * \dAp
  * Lists support functions of operator families
  *
- * Takes an optional regexps to filter by index access method and operator
+ * Takes optional regexps to filter by index access method and operator
  * family.
  */
 bool