Commit 533020d0 authored by Tom Lane's avatar Tom Lane

Fix minor issues in psql's new \dAc and related commands.

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.
parent 6ee3b5fb
...@@ -1410,6 +1410,15 @@ SELECT am.amname AS index_method, ...@@ -1410,6 +1410,15 @@ SELECT am.amname AS index_method,
ORDER BY index_method, opfamily_name, opfamily_operator; ORDER BY index_method, opfamily_name, opfamily_operator;
</programlisting> </programlisting>
</para> </para>
<tip>
<para>
<xref linkend="app-psql"/> has
commands <command>\dAc</command>, <command>\dAf</command>,
and <command>\dAo</command>, which provide slightly more sophisticated
versions of these queries.
</para>
</tip>
</sect1> </sect1>
......
...@@ -1245,13 +1245,13 @@ testdb=&gt; ...@@ -1245,13 +1245,13 @@ testdb=&gt;
<listitem> <listitem>
<para> <para>
Lists operator classes Lists operator classes
(see <xref linkend="catalog-pg-opclass"/>). (see <xref linkend="xindex-opclass"/>).
If <replaceable class="parameter">access-method-pattern</replaceable> If <replaceable class="parameter">access-method-pattern</replaceable>
is specified, only operator classes associated with access methods whose is specified, only operator classes associated with access methods whose
names match the pattern are listed. names match that pattern are listed.
If <replaceable class="parameter">input-type-pattern</replaceable> If <replaceable class="parameter">input-type-pattern</replaceable>
is specified, only operator classes associated with input types whose is specified, only operator classes associated with input types whose
names match the pattern are listed. names match that pattern are listed.
If <literal>+</literal> is appended to the command name, each operator If <literal>+</literal> is appended to the command name, each operator
class is listed with its associated operator family and owner. class is listed with its associated operator family and owner.
</para> </para>
...@@ -1268,13 +1268,13 @@ testdb=&gt; ...@@ -1268,13 +1268,13 @@ testdb=&gt;
<listitem> <listitem>
<para> <para>
Lists operator families Lists operator families
(see <xref linkend="catalog-pg-opfamily"/>). (see <xref linkend="xindex-opfamily"/>).
If <replaceable class="parameter">access-method-pattern</replaceable> If <replaceable class="parameter">access-method-pattern</replaceable>
is specified, only operator families associated with access methods whose is specified, only operator families associated with access methods whose
names match the pattern are listed. names match that pattern are listed.
If <replaceable class="parameter">input-type-pattern</replaceable> If <replaceable class="parameter">input-type-pattern</replaceable>
is specified, only operator families associated with input types whose is specified, only operator families associated with input types whose
names match the pattern are listed. names match that pattern are listed.
If <literal>+</literal> is appended to the command name, each operator If <literal>+</literal> is appended to the command name, each operator
family is listed with its owner. family is listed with its owner.
</para> </para>
...@@ -1292,15 +1292,15 @@ testdb=&gt; ...@@ -1292,15 +1292,15 @@ testdb=&gt;
<listitem> <listitem>
<para> <para>
Lists operators associated with operator families Lists operators associated with operator families
(<xref linkend="catalog-pg-amop"/>). (see <xref linkend="xindex-strategies"/>).
If <replaceable class="parameter">access-method-pattern</replaceable> If <replaceable class="parameter">access-method-pattern</replaceable>
is specified, only members of operator families associated with access is specified, only members of operator families associated with access
methods whose names match the pattern are listed. methods whose names match that pattern are listed.
If <replaceable class="parameter">input-type-pattern</replaceable> If <replaceable class="parameter">operator-family-pattern</replaceable>
is specified, only members of operator families whose names match the is specified, only members of operator families whose names match that
pattern are listed. pattern are listed.
If <literal>+</literal> is appended to the command name, each operator If <literal>+</literal> 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).
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1314,14 +1314,16 @@ testdb=&gt; ...@@ -1314,14 +1314,16 @@ testdb=&gt;
</term> </term>
<listitem> <listitem>
<para> <para>
Lists functions associated with operator families Lists support functions associated with operator families
(<xref linkend="catalog-pg-amproc"/>). (see <xref linkend="xindex-support"/>).
If <replaceable class="parameter">access-method-pattern</replaceable> If <replaceable class="parameter">access-method-pattern</replaceable>
is specified, only members of operator families associated with access is specified, only functions of operator families associated with
methods whose names match the pattern are listed. access methods whose names match that pattern are listed.
If <replaceable class="parameter">input-type-pattern</replaceable> If <replaceable class="parameter">operator-family-pattern</replaceable>
is specified, only members of operator families whose names match the is specified, only functions of operator families whose names match
pattern are listed. that pattern are listed.
If <literal>+</literal> is appended to the command name, functions are
displayed verbosely, with their actual parameter lists.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -6056,7 +6056,7 @@ printACLColumn(PQExpBuffer buf, const char *colname) ...@@ -6056,7 +6056,7 @@ printACLColumn(PQExpBuffer buf, const char *colname)
* \dAc * \dAc
* Lists operator classes * 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 bool
listOperatorClasses(const char *access_method_pattern, listOperatorClasses(const char *access_method_pattern,
...@@ -6110,6 +6110,7 @@ listOperatorClasses(const char *access_method_pattern, ...@@ -6110,6 +6110,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_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_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_type t ON t.oid = c.opcintype\n"
" LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
); );
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
...@@ -6120,8 +6121,13 @@ listOperatorClasses(const char *access_method_pattern, ...@@ -6120,8 +6121,13 @@ listOperatorClasses(const char *access_method_pattern,
have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern, have_where = processSQLNamePattern(pset.db, &buf, access_method_pattern,
false, false, NULL, "am.amname", NULL, NULL); false, false, NULL, "am.amname", NULL, NULL);
if (type_pattern) if (type_pattern)
{
/* Match type name pattern against either internal or external name */
processSQLNamePattern(pset.db, &buf, type_pattern, have_where, false, 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;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
res = PSQLexec(buf.data); res = PSQLexec(buf.data);
...@@ -6145,7 +6151,7 @@ listOperatorClasses(const char *access_method_pattern, ...@@ -6145,7 +6151,7 @@ listOperatorClasses(const char *access_method_pattern,
* \dAf * \dAf
* Lists operator families * 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 bool
listOperatorFamilies(const char *access_method_pattern, listOperatorFamilies(const char *access_method_pattern,
...@@ -6190,15 +6196,19 @@ listOperatorFamilies(const char *access_method_pattern, ...@@ -6190,15 +6196,19 @@ listOperatorFamilies(const char *access_method_pattern,
if (type_pattern) if (type_pattern)
{ {
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"\n %s EXISTS (\n" " %s EXISTS (\n"
" SELECT 1\n" " SELECT 1\n"
" FROM pg_catalog.pg_type t\n" " FROM pg_catalog.pg_type t\n"
" JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\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"); have_where ? "AND" : "WHERE");
/* Match type name pattern against either internal or external name */
processSQLNamePattern(pset.db, &buf, type_pattern, true, false, processSQLNamePattern(pset.db, &buf, type_pattern, true, false,
NULL, "t.typname", NULL, NULL); "tn.nspname", "t.typname",
appendPQExpBuffer(&buf, ")"); "pg_catalog.format_type(t.oid, NULL)",
"pg_catalog.pg_type_is_visible(t.oid)");
appendPQExpBuffer(&buf, " )\n");
} }
appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
...@@ -6223,7 +6233,7 @@ listOperatorFamilies(const char *access_method_pattern, ...@@ -6223,7 +6233,7 @@ listOperatorFamilies(const char *access_method_pattern,
* \dAo * \dAo
* Lists operators of operator families * 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. * family.
*/ */
bool bool
...@@ -6310,7 +6320,7 @@ listOpFamilyOperators(const char *access_method_pattern, ...@@ -6310,7 +6320,7 @@ listOpFamilyOperators(const char *access_method_pattern,
* \dAp * \dAp
* Lists support functions of operator families * 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. * family.
*/ */
bool bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment